Skip to content

Commit 225a143

Browse files
authored
Merge branch 'main' into importlib-nonexistent-builtin
2 parents 42974ac + fa1ac90 commit 225a143

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1258
-319
lines changed

Doc/deprecations/c-api-pending-removal-in-3.20.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
11
Pending removal in Python 3.20
22
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
33

4+
* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
5+
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
6+
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
7+
the module state, then call :c:func:`PyObject_CallMethod` or
8+
:c:func:`PyObject_GetAttr`.
9+
(Contributed by Victor Stinner in :gh:`141049`.)
10+
411
* The ``cval`` field in :c:type:`PyComplexObject` (:gh:`128813`).
512
Use :c:func:`PyComplex_AsCComplex` and :c:func:`PyComplex_FromCComplex`
613
to convert a Python complex number to/from the C :c:type:`Py_complex`

Doc/library/profiling.sampling.rst

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,11 @@ production systems. The target process requires no modification and need not
191191
be restarted. The profiler attaches, collects samples for the specified
192192
duration, then detaches and produces output.
193193

194+
::
195+
196+
python -m profiling.sampling attach --live 12345
197+
python -m profiling.sampling attach --flamegraph -d 30 -o profile.html 12345
198+
194199
On most systems, attaching to another process requires appropriate permissions.
195200
See :ref:`profiling-permissions` for platform-specific requirements.
196201

@@ -529,6 +534,25 @@ I/O-bound or waiting. The function spends most of its time waiting for network,
529534
disk, locks, or sleep. CPU optimization won't help here; consider async I/O,
530535
connection pooling, or reducing wait time instead.
531536

537+
.. code-block:: python
538+
539+
import time
540+
541+
def do_sleep():
542+
time.sleep(2)
543+
544+
def do_compute():
545+
sum(i**2 for i in range(1000000))
546+
547+
if __name__ == "__main__":
548+
do_sleep()
549+
do_compute()
550+
551+
::
552+
553+
python -m profiling.sampling run --mode=wall script.py # do_sleep ~98%, do_compute ~1%
554+
python -m profiling.sampling run --mode=cpu script.py # do_sleep absent, do_compute dominates
555+
532556

533557
GIL mode
534558
--------
@@ -553,6 +577,29 @@ GIL?" and "why are my other threads starving?" It can also be useful in
553577
single-threaded programs to distinguish Python execution time from time spent
554578
in C extensions or I/O.
555579

580+
.. code-block:: python
581+
582+
import hashlib
583+
584+
def hash_work():
585+
# C extension - releases GIL during computation
586+
for _ in range(200):
587+
hashlib.sha256(b"data" * 250000).hexdigest()
588+
589+
def python_work():
590+
# Pure Python - holds GIL during computation
591+
for _ in range(3):
592+
sum(i**2 for i in range(1000000))
593+
594+
if __name__ == "__main__":
595+
hash_work()
596+
python_work()
597+
598+
::
599+
600+
python -m profiling.sampling run --mode=cpu script.py # hash_work ~42%, python_work ~38%
601+
python -m profiling.sampling run --mode=gil script.py # hash_work ~5%, python_work ~60%
602+
556603

557604
Exception mode
558605
--------------
@@ -952,6 +999,25 @@ stack often shows event loop internals rather than the logical flow of your
952999
coroutines. Async-aware mode addresses this by tracking which task is running
9531000
and presenting stacks that reflect the ``await`` chain.
9541001

1002+
.. code-block:: python
1003+
1004+
import asyncio
1005+
1006+
async def fetch(url):
1007+
await asyncio.sleep(0.1)
1008+
return url
1009+
1010+
async def main():
1011+
for _ in range(50):
1012+
await asyncio.gather(fetch("a"), fetch("b"), fetch("c"))
1013+
1014+
if __name__ == "__main__":
1015+
asyncio.run(main())
1016+
1017+
::
1018+
1019+
python -m profiling.sampling run --async-aware --flamegraph -o out.html script.py
1020+
9551021
.. note::
9561022

9571023
Async-aware profiling requires the target process to have the :mod:`asyncio`

Doc/library/typing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2869,8 +2869,8 @@ ABCs and Protocols for working with I/O
28692869
---------------------------------------
28702870

28712871
.. class:: IO[AnyStr]
2872-
TextIO[AnyStr]
2873-
BinaryIO[AnyStr]
2872+
TextIO
2873+
BinaryIO
28742874

28752875
Generic class ``IO[AnyStr]`` and its subclasses ``TextIO(IO[str])``
28762876
and ``BinaryIO(IO[bytes])``

Doc/whatsnew/3.15.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,13 @@ Deprecated C APIs
12101210
use the :c:type:`PyBytesWriter` API instead.
12111211
(Contributed by Victor Stinner in :gh:`129813`.)
12121212

1213+
* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
1214+
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
1215+
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
1216+
the module state, then call :c:func:`PyObject_CallMethod` or
1217+
:c:func:`PyObject_GetAttr`.
1218+
(Contributed by Victor Stinner in :gh:`141049`.)
1219+
12131220
* Deprecate :c:member:`~PyComplexObject.cval` field of the
12141221
:c:type:`PyComplexObject` type.
12151222
Use :c:func:`PyComplex_AsCComplex` and :c:func:`PyComplex_FromCComplex`

Include/cpython/abstract.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
/* Like PyObject_CallMethod(), but expect a _Py_Identifier*
88
as the method name. */
9-
PyAPI_FUNC(PyObject*) _PyObject_CallMethodId(
9+
Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyObject_CallMethodId(
1010
PyObject *obj,
1111
_Py_Identifier *name,
1212
const char *format, ...);

Include/cpython/object.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ PyAPI_FUNC(void) PyUnstable_Object_Dump(PyObject *);
300300
// Alias for backward compatibility
301301
#define _PyObject_Dump PyUnstable_Object_Dump
302302

303-
PyAPI_FUNC(PyObject*) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
303+
Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyObject_GetAttrId(PyObject *, _Py_Identifier *);
304304

305305
PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
306306
PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);

Include/cpython/unicodeobject.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -778,4 +778,4 @@ static inline int Py_UNICODE_ISALNUM(Py_UCS4 ch) {
778778

779779
// Return an interned Unicode object for an Identifier; may fail if there is no
780780
// memory.
781-
PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);
781+
Py_DEPRECATED(3.15) PyAPI_FUNC(PyObject*) _PyUnicode_FromId(_Py_Identifier*);

Include/internal/pycore_opcode_metadata.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_ids.h

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Include/internal/pycore_uop_metadata.h

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)