Skip to content

Commit 55ca7b8

Browse files
authored
Merge branch 'main' into opttoken
2 parents 230e06d + cc9b9be commit 55ca7b8

File tree

439 files changed

+17583
-17528
lines changed

Some content is hidden

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

439 files changed

+17583
-17528
lines changed

.devcontainer/Dockerfile

Lines changed: 0 additions & 24 deletions
This file was deleted.

.devcontainer/devcontainer.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
{
2-
"build": {
3-
"dockerfile": "Dockerfile"
4-
},
2+
"image": "ghcr.io/python/devcontainer:2024.09.25.11038928730",
53
"onCreateCommand": [
64
// Install common tooling.
75
"dnf",

.github/CODEOWNERS

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,6 @@ Doc/c-api/stable.rst @encukou
207207
**/*bisect* @rhettinger
208208
**/*heapq* @rhettinger
209209
**/*functools* @rhettinger
210-
**/*decimal* @rhettinger
211210

212211
**/*dataclasses* @ericvsmith
213212

.github/ISSUE_TEMPLATE/crash.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ body:
3232
- "3.10"
3333
- "3.11"
3434
- "3.12"
35+
- "3.13"
3536
- "CPython main branch"
3637
validations:
3738
required: true

Doc/Makefile

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,15 @@ serve:
305305

306306
# for development releases: always build
307307
.PHONY: autobuild-dev
308+
autobuild-dev: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
308309
autobuild-dev:
309-
$(MAKE) dist SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1'
310+
$(MAKE) dist-no-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
310311

311-
# for quick rebuilds (HTML only)
312+
# for HTML-only rebuilds
312313
.PHONY: autobuild-dev-html
314+
autobuild-dev-html: DISTVERSION = $(shell $(PYTHON) tools/extensions/patchlevel.py --short)
313315
autobuild-dev-html:
314-
$(MAKE) html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1'
316+
$(MAKE) dist-html SPHINXOPTS='$(SPHINXOPTS) -Ea -A daily=1' DISTVERSION=$(DISTVERSION)
315317

316318
# for stable releases: only build if not in pre-release stage (alpha, beta)
317319
# release candidate downloads are okay, since the stable tree can be in that stage

Doc/c-api/exceptions.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ Exception Classes
733733
This creates a class object derived from :exc:`Exception` (accessible in C as
734734
:c:data:`PyExc_Exception`).
735735
736-
The :attr:`!__module__` attribute of the new class is set to the first part (up
736+
The :attr:`~type.__module__` attribute of the new class is set to the first part (up
737737
to the last dot) of the *name* argument, and the class name is set to the last
738738
part (after the last dot). The *base* argument can be used to specify alternate
739739
base classes; it can either be only one class or a tuple of classes. The *dict*

Doc/c-api/init.rst

Lines changed: 61 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,11 @@ Initializing and finalizing the interpreter
430430
Some memory allocated by extension modules may not be freed. Some extensions may not
431431
work properly if their initialization routine is called more than once; this can
432432
happen if an application calls :c:func:`Py_Initialize` and :c:func:`Py_FinalizeEx`
433-
more than once.
433+
more than once. :c:func:`Py_FinalizeEx` must not be called recursively from
434+
within itself. Therefore, it must not be called by any code that may be run
435+
as part of the interpreter shutdown process, such as :py:mod:`atexit`
436+
handlers, object finalizers, or any code that may be run while flushing the
437+
stdout and stderr files.
434438

435439
.. audit-event:: cpython._PySys_ClearAuditHooks "" c.Py_FinalizeEx
436440

@@ -960,6 +964,37 @@ thread, where the CPython global runtime was originally initialized.
960964
The only exception is if :c:func:`exec` will be called immediately
961965
after.
962966
967+
.. _cautions-regarding-runtime-finalization:
968+
969+
Cautions regarding runtime finalization
970+
---------------------------------------
971+
972+
In the late stage of :term:`interpreter shutdown`, after attempting to wait for
973+
non-daemon threads to exit (though this can be interrupted by
974+
:class:`KeyboardInterrupt`) and running the :mod:`atexit` functions, the runtime
975+
is marked as *finalizing*: :c:func:`_Py_IsFinalizing` and
976+
:func:`sys.is_finalizing` return true. At this point, only the *finalization
977+
thread* that initiated finalization (typically the main thread) is allowed to
978+
acquire the :term:`GIL`.
979+
980+
If any thread, other than the finalization thread, attempts to acquire the GIL
981+
during finalization, either explicitly via :c:func:`PyGILState_Ensure`,
982+
:c:macro:`Py_END_ALLOW_THREADS`, :c:func:`PyEval_AcquireThread`, or
983+
:c:func:`PyEval_AcquireLock`, or implicitly when the interpreter attempts to
984+
reacquire it after having yielded it, the thread enters **a permanently blocked
985+
state** where it remains until the program exits. In most cases this is
986+
harmless, but this can result in deadlock if a later stage of finalization
987+
attempts to acquire a lock owned by the blocked thread, or otherwise waits on
988+
the blocked thread.
989+
990+
Gross? Yes. This prevents random crashes and/or unexpectedly skipped C++
991+
finalizations further up the call stack when such threads were forcibly exited
992+
here in CPython 3.13 and earlier. The CPython runtime GIL acquiring C APIs
993+
have never had any error reporting or handling expectations at GIL acquisition
994+
time that would've allowed for graceful exit from this situation. Changing that
995+
would require new stable C APIs and rewriting the majority of C code in the
996+
CPython ecosystem to use those with error handling.
997+
963998
964999
High-level API
9651000
--------------
@@ -1033,11 +1068,14 @@ code, or when embedding the Python interpreter:
10331068
ensues.
10341069
10351070
.. note::
1036-
Calling this function from a thread when the runtime is finalizing
1037-
will terminate the thread, even if the thread was not created by Python.
1038-
You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
1039-
check if the interpreter is in process of being finalized before calling
1040-
this function to avoid unwanted termination.
1071+
Calling this function from a thread when the runtime is finalizing will
1072+
hang the thread until the program exits, even if the thread was not
1073+
created by Python. Refer to
1074+
:ref:`cautions-regarding-runtime-finalization` for more details.
1075+
1076+
.. versionchanged:: next
1077+
Hangs the current thread, rather than terminating it, if called while the
1078+
interpreter is finalizing.
10411079
10421080
.. c:function:: PyThreadState* PyThreadState_Get()
10431081
@@ -1092,11 +1130,14 @@ with sub-interpreters:
10921130
to call arbitrary Python code. Failure is a fatal error.
10931131
10941132
.. note::
1095-
Calling this function from a thread when the runtime is finalizing
1096-
will terminate the thread, even if the thread was not created by Python.
1097-
You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
1098-
check if the interpreter is in process of being finalized before calling
1099-
this function to avoid unwanted termination.
1133+
Calling this function from a thread when the runtime is finalizing will
1134+
hang the thread until the program exits, even if the thread was not
1135+
created by Python. Refer to
1136+
:ref:`cautions-regarding-runtime-finalization` for more details.
1137+
1138+
.. versionchanged:: next
1139+
Hangs the current thread, rather than terminating it, if called while the
1140+
interpreter is finalizing.
11001141
11011142
.. c:function:: void PyGILState_Release(PyGILState_STATE)
11021143
@@ -1224,7 +1265,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
12241265
.. c:function:: void PyThreadState_DeleteCurrent(void)
12251266
12261267
Destroy the current thread state and release the global interpreter lock.
1227-
Like :c:func:`PyThreadState_Delete`, the global interpreter lock need not
1268+
Like :c:func:`PyThreadState_Delete`, the global interpreter lock must
12281269
be held. The thread state must have been reset with a previous call
12291270
to :c:func:`PyThreadState_Clear`.
12301271
@@ -1374,17 +1415,20 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
13741415
If this thread already has the lock, deadlock ensues.
13751416
13761417
.. note::
1377-
Calling this function from a thread when the runtime is finalizing
1378-
will terminate the thread, even if the thread was not created by Python.
1379-
You can use :c:func:`Py_IsFinalizing` or :func:`sys.is_finalizing` to
1380-
check if the interpreter is in process of being finalized before calling
1381-
this function to avoid unwanted termination.
1418+
Calling this function from a thread when the runtime is finalizing will
1419+
hang the thread until the program exits, even if the thread was not
1420+
created by Python. Refer to
1421+
:ref:`cautions-regarding-runtime-finalization` for more details.
13821422
13831423
.. versionchanged:: 3.8
13841424
Updated to be consistent with :c:func:`PyEval_RestoreThread`,
13851425
:c:func:`Py_END_ALLOW_THREADS`, and :c:func:`PyGILState_Ensure`,
13861426
and terminate the current thread if called while the interpreter is finalizing.
13871427
1428+
.. versionchanged:: next
1429+
Hangs the current thread, rather than terminating it, if called while the
1430+
interpreter is finalizing.
1431+
13881432
:c:func:`PyEval_RestoreThread` is a higher-level function which is always
13891433
available (even when threads have not been initialized).
13901434

Doc/c-api/init_config.rst

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,19 +1248,24 @@ PyConfig
12481248
12491249
.. c:member:: int perf_profiling
12501250
1251-
Enable compatibility mode with the perf profiler?
1251+
Enable the Linux ``perf`` profiler support?
12521252
1253-
If non-zero, initialize the perf trampoline. See :ref:`perf_profiling`
1254-
for more information.
1253+
If equals to ``1``, enable support for the Linux ``perf`` profiler.
12551254
1256-
Set by :option:`-X perf <-X>` command-line option and by the
1257-
:envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable for perf support
1258-
with stack pointers and :option:`-X perf_jit <-X>` command-line option
1259-
and by the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable for perf
1260-
support with DWARF JIT information.
1255+
If equals to ``2``, enable support for the Linux ``perf`` profiler with
1256+
DWARF JIT support.
1257+
1258+
Set to ``1`` by :option:`-X perf <-X>` command-line option and the
1259+
:envvar:`PYTHONPERFSUPPORT` environment variable.
1260+
1261+
Set to ``2`` by the :option:`-X perf_jit <-X>` command-line option and
1262+
the :envvar:`PYTHON_PERF_JIT_SUPPORT` environment variable.
12611263
12621264
Default: ``-1``.
12631265
1266+
.. seealso::
1267+
See :ref:`perf_profiling` for more information.
1268+
12641269
.. versionadded:: 3.12
12651270
12661271
.. c:member:: int use_environment

Doc/c-api/long.rst

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,6 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
159159
.. versionadded:: 3.13
160160
161161
162-
.. XXX alias PyLong_AS_LONG (for now)
163162
.. c:function:: long PyLong_AsLong(PyObject *obj)
164163
165164
.. index::
@@ -181,6 +180,16 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
181180
.. versionchanged:: 3.10
182181
This function will no longer use :meth:`~object.__int__`.
183182
183+
.. c:namespace:: NULL
184+
185+
.. c:function:: long PyLong_AS_LONG(PyObject *obj)
186+
187+
A :term:`soft deprecated` alias.
188+
Exactly equivalent to the preferred ``PyLong_AsLong``. In particular,
189+
it can fail with :exc:`OverflowError` or another exception.
190+
191+
.. deprecated:: 3.14
192+
The function is soft deprecated.
184193
185194
.. c:function:: int PyLong_AsInt(PyObject *obj)
186195
@@ -570,7 +579,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
570579
On failure, return -1 with an exception set. This function always succeeds
571580
if *obj* is a :c:type:`PyLongObject` or its subtype.
572581
573-
.. versionadded:: 3.14
582+
.. versionadded:: next
574583
575584
576585
.. c:function:: PyObject* PyLong_GetInfo(void)

Doc/c-api/object.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -367,14 +367,14 @@ Object Protocol
367367
The result will be ``1`` when at least one of the checks returns ``1``,
368368
otherwise it will be ``0``.
369369
370-
If *cls* has a :meth:`~class.__subclasscheck__` method, it will be called to
370+
If *cls* has a :meth:`~type.__subclasscheck__` method, it will be called to
371371
determine the subclass status as described in :pep:`3119`. Otherwise,
372372
*derived* is a subclass of *cls* if it is a direct or indirect subclass,
373-
i.e. contained in ``cls.__mro__``.
373+
i.e. contained in :attr:`cls.__mro__ <type.__mro__>`.
374374
375375
Normally only class objects, i.e. instances of :class:`type` or a derived
376376
class, are considered classes. However, objects can override this by having
377-
a :attr:`~class.__bases__` attribute (which must be a tuple of base classes).
377+
a :attr:`~type.__bases__` attribute (which must be a tuple of base classes).
378378
379379
380380
.. c:function:: int PyObject_IsInstance(PyObject *inst, PyObject *cls)
@@ -386,15 +386,15 @@ Object Protocol
386386
The result will be ``1`` when at least one of the checks returns ``1``,
387387
otherwise it will be ``0``.
388388
389-
If *cls* has a :meth:`~class.__instancecheck__` method, it will be called to
389+
If *cls* has a :meth:`~type.__instancecheck__` method, it will be called to
390390
determine the subclass status as described in :pep:`3119`. Otherwise, *inst*
391391
is an instance of *cls* if its class is a subclass of *cls*.
392392
393393
An instance *inst* can override what is considered its class by having a
394-
:attr:`~instance.__class__` attribute.
394+
:attr:`~object.__class__` attribute.
395395
396396
An object *cls* can override if it is considered a class, and what its base
397-
classes are, by having a :attr:`~class.__bases__` attribute (which must be a tuple
397+
classes are, by having a :attr:`~type.__bases__` attribute (which must be a tuple
398398
of base classes).
399399
400400

0 commit comments

Comments
 (0)