Skip to content

Commit 18217d3

Browse files
Merge remote-tracking branch 'upstream/main' into cleanups_refcount
2 parents ec5a67c + c90863a commit 18217d3

File tree

65 files changed

+1476
-337
lines changed

Some content is hidden

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

65 files changed

+1476
-337
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/argparse.rst

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,27 @@ are set.
645645

646646
.. versionadded:: 3.14
647647

648+
To highlight inline code in your description or epilog text, you can use
649+
backticks::
650+
651+
>>> parser = argparse.ArgumentParser(
652+
... formatter_class=argparse.RawDescriptionHelpFormatter,
653+
... epilog='''Examples:
654+
... `python -m myapp --verbose`
655+
... `python -m myapp --config settings.json`
656+
... ''')
657+
658+
When colors are enabled, the text inside backticks will be displayed in a
659+
distinct color to help examples stand out. When colors are disabled, backticks
660+
are preserved as-is, which is readable in plain text.
661+
662+
.. note::
663+
664+
Backtick markup only applies to description and epilog text. It does not
665+
apply to individual argument ``help`` strings.
666+
667+
.. versionadded:: 3.15
668+
648669

649670
The add_argument() method
650671
-------------------------

Doc/library/importlib.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,12 @@ Functions
210210
:exc:`ModuleNotFoundError` is raised when the module being reloaded lacks
211211
a :class:`~importlib.machinery.ModuleSpec`.
212212

213+
.. versionchanged:: next
214+
If *module* is a lazy module that has not yet been materialized (i.e.,
215+
loaded via :class:`importlib.util.LazyLoader` and not yet accessed),
216+
calling :func:`reload` is a no-op and returns the module unchanged.
217+
This prevents the reload from unintentionally triggering the lazy load.
218+
213219
.. warning::
214220
This function is not thread-safe. Calling it from multiple threads can result
215221
in unexpected behavior. It's recommended to use the :class:`threading.Lock`

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: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -423,6 +423,10 @@ argparse
423423
default to ``True``. This enables suggestions for mistyped arguments by default.
424424
(Contributed by Jakob Schluse in :gh:`140450`.)
425425

426+
* Added backtick markup support in description and epilog text to highlight
427+
inline code when color output is enabled.
428+
(Contributed by Savannah Ostrowski in :gh:`142390`.)
429+
426430
calendar
427431
--------
428432

@@ -1210,6 +1214,13 @@ Deprecated C APIs
12101214
use the :c:type:`PyBytesWriter` API instead.
12111215
(Contributed by Victor Stinner in :gh:`129813`.)
12121216

1217+
* :c:func:`!_PyObject_CallMethodId`, :c:func:`!_PyObject_GetAttrId` and
1218+
:c:func:`!_PyUnicode_FromId` are deprecated since 3.15 and will be removed in
1219+
3.20. Instead, use :c:func:`PyUnicode_FromString()` and cache the result in
1220+
the module state, then call :c:func:`PyObject_CallMethod` or
1221+
:c:func:`PyObject_GetAttr`.
1222+
(Contributed by Victor Stinner in :gh:`141049`.)
1223+
12131224
* Deprecate :c:member:`~PyComplexObject.cval` field of the
12141225
:c:type:`PyComplexObject` type.
12151226
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.

0 commit comments

Comments
 (0)