Skip to content

Commit 9935ba9

Browse files
Merge branch 'python:main' into gh-131178-zipapp-cli-tests
2 parents 2a31466 + a52f428 commit 9935ba9

159 files changed

Lines changed: 7693 additions & 737 deletions

File tree

Some content is hidden

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

.github/CODEOWNERS

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@
6363
.azure-pipelines/ @AA-Turner
6464

6565
# GitHub & related scripts
66-
.github/ @ezio-melotti @hugovk @AA-Turner @webknjaz @itamaro
66+
.github/ @ezio-melotti @hugovk @AA-Turner @webknjaz @itamaro @JacobCoffee
6767
Tools/build/compute-changes.py @AA-Turner @hugovk @webknjaz
6868
Lib/test/test_tools/test_compute_changes.py @AA-Turner @hugovk @webknjaz
6969
Tools/build/verify_ensurepip_wheels.py @AA-Turner @pfmoore @pradyunsg
7070

7171
# Pre-commit
72-
.pre-commit-config.yaml @hugovk
73-
.ruff.toml @hugovk @AlexWaygood @AA-Turner
72+
.pre-commit-config.yaml @hugovk @JacobCoffee
73+
.ruff.toml @hugovk @AlexWaygood @AA-Turner @JacobCoffee
7474

7575
# Patchcheck
7676
Tools/patchcheck/ @AA-Turner @itamaro

.github/workflows/jit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ jobs:
6464
include:
6565
- target: i686-pc-windows-msvc/msvc
6666
architecture: Win32
67-
runner: windows-2025-vs2026
67+
runner: windows-2025
6868
- target: x86_64-pc-windows-msvc/msvc
6969
architecture: x64
70-
runner: windows-2025-vs2026
70+
runner: windows-2025
7171
- target: aarch64-pc-windows-msvc/msvc
7272
architecture: ARM64
7373
runner: windows-11-arm

.github/workflows/reusable-windows-msi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ env:
1717
jobs:
1818
build:
1919
name: installer for ${{ inputs.arch }}
20-
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2025-vs2026' }}
20+
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2025' }}
2121
timeout-minutes: 60
2222
env:
2323
ARCH: ${{ inputs.arch }}

.github/workflows/reusable-windows.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ env:
2626
jobs:
2727
build:
2828
name: Build and test (${{ inputs.arch }}, ${{ inputs.interpreter }})
29-
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2025-vs2026' }}
29+
runs-on: ${{ inputs.arch == 'arm64' && 'windows-11-arm' || 'windows-2025' }}
3030
timeout-minutes: 60
3131
env:
3232
ARCH: ${{ inputs.arch }}

Doc/c-api/extension-modules.rst

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,35 @@ For example, a module called ``spam`` would be defined like this::
100100
The export hook is typically the only non-\ ``static``
101101
item defined in the module's C source.
102102

103-
The hook should be kept short -- ideally, one line as above.
104-
If you do need to use Python C API in this function, it is recommended to call
105-
``PyABIInfo_Check(&abi_info, "modulename")`` first to raise an exception,
106-
rather than crash, in common cases of ABI mismatch.
103+
.. _pymodexport-api-caveats:
107104

105+
The hook should be kept short.
106+
If it does more than ``return`` a static array, several caveats apply:
107+
108+
- If you need to use any Python C API, it is recommended to call
109+
:c:func:`PyABIInfo_Check` first to raise an exception,
110+
rather than crash, in common cases of ABI mismatch.
111+
- Code in the export hook must never rely on the :term:`GIL`:
112+
:term:`free-threaded builds <free-threaded build>` of Python can only check
113+
the :c:macro:`Py_mod_gil` slot (or the lack of it) after the hook returns,
114+
- Similarly, the hook may be called in any subinterpreter, since the
115+
:c:macro:`Py_mod_multiple_interpreters` slot (or lack of it)
116+
is only checked after the hook returns.
117+
118+
For example::
119+
120+
PyMODEXPORT_FUNC
121+
PyModExport_modulename(void)
122+
{
123+
if (PyABIInfo_Check(&abi_info, "modulename") < 0) {
124+
/* ABI mismatch. It's not safe to examine the raised exception. */
125+
return NULL;
126+
}
127+
128+
/* use Python API (as little as possible); don't rely on GIL */
129+
130+
return modulename_slots;
131+
}
108132

109133
.. note::
110134

Doc/c-api/import.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,11 @@ Importing Modules
304304
305305
Initialization function for a module built into the interpreter.
306306
307+
Note that the inittab uses "``PyInit``"
308+
:ref:`initialization functions <extension-pyinit>`;
309+
there is currently no way to include "``PyModExport_``"
310+
:ref:`export hooks <extension-export-hook>`.
311+
307312
308313
.. c:function:: int PyImport_ExtendInittab(struct _inittab *newtab)
309314

Doc/deprecations/index.rst

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
Deprecations
22
============
33

4-
.. include:: pending-removal-in-3.16.rst
5-
64
.. include:: pending-removal-in-3.17.rst
75

86
.. include:: pending-removal-in-3.18.rst
@@ -20,8 +18,6 @@ Deprecations
2018
C API deprecations
2119
------------------
2220

23-
.. include:: c-api-pending-removal-in-3.16.rst
24-
2521
.. include:: c-api-pending-removal-in-3.18.rst
2622

2723
.. include:: c-api-pending-removal-in-3.19.rst

Doc/extending/extending.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -231,10 +231,8 @@ calling the Python callback functions from a C callback. Other uses are also
231231
imaginable.
232232

233233
Fortunately, the Python interpreter is easily called recursively, and there is a
234-
standard interface to call a Python function. (I won't dwell on how to call the
235-
Python parser with a particular string as input --- if you're interested, have a
236-
look at the implementation of the :option:`-c` command line option in
237-
:file:`Modules/main.c` from the Python source code.)
234+
standard interface to call a Python function. (If you're interested in how to call the
235+
Python parser with a particular string as input, see :ref:`veryhigh`.)
238236

239237
Calling a Python function is easy. First, the Python program must somehow pass
240238
you the Python function object. You should provide a function (or some other
@@ -641,7 +639,7 @@ and the object is freed.
641639

642640
An alternative strategy is called :dfn:`automatic garbage collection`.
643641
(Sometimes, reference counting is also referred to as a garbage collection
644-
strategy, hence my use of "automatic" to distinguish the two.) The big
642+
strategy, hence the use of "automatic" to distinguish the two.) The big
645643
advantage of automatic garbage collection is that the user doesn't need to call
646644
:c:func:`free` explicitly. (Another claimed advantage is an improvement in speed
647645
or memory usage --- this is no hard fact however.) The disadvantage is that for

Doc/howto/abi3t-migration.rst

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ versions you support.
210210
This will ensure that nothing breaks as you are porting.
211211

212212

213+
.. _abi3t-howto-modexport:
214+
213215
Module export hook
214216
==================
215217

@@ -290,6 +292,104 @@ and substitute your own values.
290292
See the :c:type:`PySlot` and :c:ref:`export hook <extension-export-hook>`
291293
documentation for details on this API.
292294

295+
As in the example, your ``PyModExport_`` function should *only* return a
296+
pointer to static data.
297+
If you cannot avoid additional code, refer to the
298+
:ref:`caveats in PyModExport documentation <pymodexport-api-caveats>`.
299+
300+
301+
Existing slots
302+
--------------
303+
304+
If you have a ``Py_mod_slots`` slot, check the array it refers to.
305+
It should be a :c:type:`PyModuleDef_Slot` array like the following:
306+
307+
.. code-block::
308+
:class: bad
309+
310+
static PyObject *create_module(PyObject *spec, PyModuleDef *def) { ... }
311+
static int my_first_module_exec(PyObject *module) { ... }
312+
static int my_second_module_exec(PyObject *module) { ... }
313+
314+
static PyModuleDef_Slot my_slots[] = {
315+
{Py_mod_gil, Py_MOD_GIL_NOT_USED},
316+
{Py_mod_multiple_interpreters, Py_MOD_PER_INTERPRETER_GIL_SUPPORTED},
317+
{Py_mod_create, my_module_create},
318+
{Py_mod_exec, my_first_module_exec},
319+
{Py_mod_exec, my_second_module_exec},
320+
{0, NULL}
321+
};
322+
323+
``py_mod_create``
324+
.................
325+
326+
327+
If you have a :c:macro:`Py_mod_create` entry, make sure the function can be
328+
called with ``NULL`` as its second argument (instead of the
329+
:c:type:`PyModuleDef`, which you are removing).
330+
Often, this argument isn't used at all; you can check by renaming it:
331+
332+
.. code-block::
333+
:class: good
334+
335+
static PyObject *create_module(PyObject *spec, PyModuleDef *_unused) { ... }
336+
337+
If the argument is used, find a different way to pass in the data.
338+
Commonly, the information is static and you can refer to it directly.
339+
(If you're reusing a single function for several different modules, consider
340+
defining several functions instead.)
341+
342+
343+
Multiple ``py_mod_exec``
344+
........................
345+
346+
If you have *more than one* :c:macro:`Py_mod_exec` entry, consolidate them:
347+
create a new function that calls the others, and replace existing slots
348+
with it.
349+
350+
.. code-block::
351+
:class: good
352+
353+
static int my_module_exec(PyObject *module) {
354+
if (my_first_module_exec(module) < 0) return -1;
355+
if (my_second_module_exec(module) < 0) return -1;
356+
}
357+
358+
static PyModuleDef_Slot my_slots[] = {
359+
...
360+
/* (remove other Py_mod_exec slots) */
361+
...
362+
{Py_mod_exec, my_module_exec},
363+
{0, NULL}
364+
};
365+
366+
If the functions aren't used elsewhere, you can combine their bodies instead.
367+
368+
369+
Merging slot arrays
370+
...................
371+
372+
Optionally, when you break compatibility with Python 3.14, you may clean up
373+
the code by moving slots into the :c:type:`PySlot` array, and converting the
374+
definitions to :c:macro:`PySlot_DATA` and :c:macro:`PySlot_FUNC`:
375+
376+
.. code-block::
377+
:class: good
378+
379+
static PySlot my_slot_array[] = {
380+
...
381+
PySlot_DATA(Py_mod_gil, Py_MOD_GIL_NOT_USED),
382+
PySlot_DATA(Py_mod_multiple_interpreters,
383+
Py_MOD_PER_INTERPRETER_GIL_SUPPORTED)
384+
PySlot_FUNC(Py_mod_create, my_module_create),
385+
PySlot_FUNC(Py_mod_exec, my_module_exec),
386+
PySlot_END
387+
};
388+
389+
If you do this, delete the original :c:type:`PyModuleDef_Slot` array and
390+
its ``Py_mod_slots`` entry.
391+
392+
293393
Associated ``PyModuleDef``
294394
--------------------------
295395

@@ -483,7 +583,7 @@ For example, if a user makes a subclass like this:
483583
class Sub(YourCustomClass):
484584
__slots__ = ('a', 'b')
485585
486-
then ``Py_TYPE(obj)`` is ``YourCustomClass``, and the underlying memory may
586+
then ``Py_TYPE(obj)`` is ``Sub``, and the underlying memory may
487587
look like this:
488588

489589
.. code-block:: text

Doc/library/codecs.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1399,6 +1399,14 @@ encodings.
13991399
| punycode | | Implement :rfc:`3492`. |
14001400
| | | Stateful codecs are not |
14011401
| | | supported. |
1402+
| | | |
1403+
| | | .. warning:: |
1404+
| | | |
1405+
| | | The decoding and |
1406+
| | | encoding algorithms |
1407+
| | | scale poorly, so |
1408+
| | | limit the length of |
1409+
| | | untrusted input. |
14021410
+--------------------+---------+---------------------------+
14031411
| raw_unicode_escape | | Latin-1 encoding with |
14041412
| | | :samp:`\\u{XXXX}` and |

0 commit comments

Comments
 (0)