Skip to content

Commit ffd95c6

Browse files
Merge branch 'main' into gh-108009
2 parents a52fd96 + 8a2baed commit ffd95c6

File tree

155 files changed

+3071
-1455
lines changed

Some content is hidden

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

155 files changed

+3071
-1455
lines changed

.github/CODEOWNERS

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ Python/compile.c @markshannon @iritkatriel
3838
Python/assemble.c @markshannon @iritkatriel
3939
Python/flowgraph.c @markshannon @iritkatriel
4040
Python/instruction_sequence.c @iritkatriel
41-
Python/ast_opt.c @isidentical
4241
Python/bytecodes.c @markshannon
4342
Python/optimizer*.c @markshannon
4443
Python/optimizer_analysis.c @Fidget-Spinner
@@ -158,10 +157,12 @@ Include/internal/pycore_time.h @pganssle @abalkin
158157
/Tools/cases_generator/ @markshannon
159158

160159
# AST
161-
Python/ast.c @isidentical @JelleZijlstra
162-
Parser/asdl.py @isidentical @JelleZijlstra
163-
Parser/asdl_c.py @isidentical @JelleZijlstra
164-
Lib/ast.py @isidentical @JelleZijlstra
160+
Python/ast.c @isidentical @JelleZijlstra @eclips4
161+
Python/ast_opt.c @isidentical @eclips4
162+
Parser/asdl.py @isidentical @JelleZijlstra @eclips4
163+
Parser/asdl_c.py @isidentical @JelleZijlstra @eclips4
164+
Lib/ast.py @isidentical @JelleZijlstra @eclips4
165+
Lib/test/test_ast/ @eclips4
165166

166167
# Mock
167168
/Lib/unittest/mock.py @cjw296

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
repos:
22
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
rev: v0.4.10
3+
rev: v0.6.7
44
hooks:
55
- id: ruff
66
name: Run Ruff (lint) on Doc/

Doc/Makefile

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ htmlview: html
152152
$(PYTHON) -c "import os, webbrowser; webbrowser.open('file://' + os.path.realpath('build/html/index.html'))"
153153

154154
.PHONY: htmllive
155-
htmllive: SPHINXBUILD = $(VENVDIR)/bin/sphinx-autobuild
155+
htmllive: SPHINXBUILD = PATH=$(VENVDIR)/bin:$$PATH sphinx-autobuild
156156
htmllive: SPHINXOPTS = --re-ignore="/venv/" --open-browser --delay 0
157157
htmllive: _ensure-sphinx-autobuild html
158158

@@ -182,13 +182,26 @@ venv:
182182
echo "The venv has been created in the $(VENVDIR) directory"; \
183183
fi
184184

185+
.PHONY: dist-no-html
186+
dist-no-html: dist-text dist-pdf dist-epub dist-texinfo
187+
185188
.PHONY: dist
186189
dist:
187190
rm -rf dist
188191
mkdir -p dist
189-
192+
$(MAKE) dist-html
193+
$(MAKE) dist-text
194+
$(MAKE) dist-pdf
195+
$(MAKE) dist-epub
196+
$(MAKE) dist-texinfo
197+
198+
.PHONY: dist-html
199+
dist-html:
190200
# archive the HTML
191201
@echo "Building HTML..."
202+
mkdir -p dist
203+
rm -rf build/html
204+
find dist -name 'python-$(DISTVERSION)-docs-html*' -exec rm -rf {} \;
192205
$(MAKE) html
193206
cp -pPR build/html dist/python-$(DISTVERSION)-docs-html
194207
tar -C dist -cf dist/python-$(DISTVERSION)-docs-html.tar python-$(DISTVERSION)-docs-html
@@ -198,8 +211,13 @@ dist:
198211
rm dist/python-$(DISTVERSION)-docs-html.tar
199212
@echo "Build finished and archived!"
200213

214+
.PHONY: dist-text
215+
dist-text:
201216
# archive the text build
202217
@echo "Building text..."
218+
mkdir -p dist
219+
rm -rf build/text
220+
find dist -name 'python-$(DISTVERSION)-docs-text*' -exec rm -rf {} \;
203221
$(MAKE) text
204222
cp -pPR build/text dist/python-$(DISTVERSION)-docs-text
205223
tar -C dist -cf dist/python-$(DISTVERSION)-docs-text.tar python-$(DISTVERSION)-docs-text
@@ -209,9 +227,13 @@ dist:
209227
rm dist/python-$(DISTVERSION)-docs-text.tar
210228
@echo "Build finished and archived!"
211229

230+
.PHONY: dist-pdf
231+
dist-pdf:
212232
# archive the A4 latex
213233
@echo "Building LaTeX (A4 paper)..."
234+
mkdir -p dist
214235
rm -rf build/latex
236+
find dist -name 'python-$(DISTVERSION)-docs-pdf*' -exec rm -rf {} \;
215237
$(MAKE) latex PAPER=a4
216238
# remove zip & bz2 dependency on all-pdf,
217239
# as otherwise the full latexmk process is run twice.
@@ -222,16 +244,24 @@ dist:
222244
cp build/latex/docs-pdf.tar.bz2 dist/python-$(DISTVERSION)-docs-pdf-a4.tar.bz2
223245
@echo "Build finished and archived!"
224246

247+
.PHONY: dist-epub
248+
dist-epub:
225249
# copy the epub build
226250
@echo "Building EPUB..."
251+
mkdir -p dist
227252
rm -rf build/epub
253+
rm -f dist/python-$(DISTVERSION)-docs.epub
228254
$(MAKE) epub
229255
cp -pPR build/epub/Python.epub dist/python-$(DISTVERSION)-docs.epub
230256
@echo "Build finished and archived!"
231257

258+
.PHONY: dist-texinfo
259+
dist-texinfo:
232260
# archive the texinfo build
233261
@echo "Building Texinfo..."
262+
mkdir -p dist
234263
rm -rf build/texinfo
264+
find dist -name 'python-$(DISTVERSION)-docs-texinfo*' -exec rm -rf {} \;
235265
$(MAKE) texinfo
236266
$(MAKE) info --directory=build/texinfo
237267
cp -pPR build/texinfo dist/python-$(DISTVERSION)-docs-texinfo

Doc/c-api/complex.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,8 @@ pointers. This is consistent throughout the API.
7979
If *num* is null and *exp* is not a positive real number,
8080
this method returns zero and sets :c:data:`errno` to :c:macro:`!EDOM`.
8181
82+
Set :c:data:`errno` to :c:macro:`!ERANGE` on overflows.
83+
8284
8385
Complex Numbers as Python Objects
8486
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Doc/c-api/exceptions.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,6 +1004,7 @@ the variables:
10041004
single: PyExc_OverflowError (C var)
10051005
single: PyExc_PermissionError (C var)
10061006
single: PyExc_ProcessLookupError (C var)
1007+
single: PyExc_PythonFinalizationError (C var)
10071008
single: PyExc_RecursionError (C var)
10081009
single: PyExc_ReferenceError (C var)
10091010
single: PyExc_RuntimeError (C var)
@@ -1096,6 +1097,8 @@ the variables:
10961097
+-----------------------------------------+---------------------------------+----------+
10971098
| :c:data:`PyExc_ProcessLookupError` | :exc:`ProcessLookupError` | |
10981099
+-----------------------------------------+---------------------------------+----------+
1100+
| :c:data:`PyExc_PythonFinalizationError` | :exc:`PythonFinalizationError` | |
1101+
+-----------------------------------------+---------------------------------+----------+
10991102
| :c:data:`PyExc_RecursionError` | :exc:`RecursionError` | |
11001103
+-----------------------------------------+---------------------------------+----------+
11011104
| :c:data:`PyExc_ReferenceError` | :exc:`ReferenceError` | |

Doc/c-api/long.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,8 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
509509
Currently, ``-1`` corresponds to
510510
``Py_ASNATIVEBYTES_NATIVE_ENDIAN | Py_ASNATIVEBYTES_UNSIGNED_BUFFER``.
511511
512+
.. c:namespace:: NULL
513+
512514
============================================= ======
513515
Flag Value
514516
============================================= ======

Doc/c-api/module.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,8 @@ The available slot types are:
421421
422422
Specifies one of the following values:
423423
424+
.. c:namespace:: NULL
425+
424426
.. c:macro:: Py_MOD_GIL_USED
425427
426428
The module depends on the presence of the global interpreter lock (GIL),

Doc/c-api/monitoring.rst

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.. highlight:: c
22

3-
.. _monitoring:
3+
.. _c-api-monitoring:
44

55
Monitoring C API
66
================
@@ -133,32 +133,60 @@ Managing the Monitoring State
133133
Monitoring states can be managed with the help of monitoring scopes. A scope
134134
would typically correspond to a python function.
135135
136-
.. :c:function:: int PyMonitoring_EnterScope(PyMonitoringState *state_array, uint64_t *version, const uint8_t *event_types, Py_ssize_t length)
136+
.. c:function:: int PyMonitoring_EnterScope(PyMonitoringState *state_array, uint64_t *version, const uint8_t *event_types, Py_ssize_t length)
137137
138138
Enter a monitored scope. ``event_types`` is an array of the event IDs for
139139
events that may be fired from the scope. For example, the ID of a ``PY_START``
140140
event is the value ``PY_MONITORING_EVENT_PY_START``, which is numerically equal
141141
to the base-2 logarithm of ``sys.monitoring.events.PY_START``.
142142
``state_array`` is an array with a monitoring state entry for each event in
143143
``event_types``, it is allocated by the user but populated by
144-
``PyMonitoring_EnterScope`` with information about the activation state of
144+
:c:func:`!PyMonitoring_EnterScope` with information about the activation state of
145145
the event. The size of ``event_types`` (and hence also of ``state_array``)
146146
is given in ``length``.
147147
148148
The ``version`` argument is a pointer to a value which should be allocated
149149
by the user together with ``state_array`` and initialized to 0,
150-
and then set only by ``PyMonitoring_EnterScope`` itelf. It allows this
150+
and then set only by :c:func:`!PyMonitoring_EnterScope` itelf. It allows this
151151
function to determine whether event states have changed since the previous call,
152152
and to return quickly if they have not.
153153
154154
The scopes referred to here are lexical scopes: a function, class or method.
155-
``PyMonitoring_EnterScope`` should be called whenever the lexical scope is
155+
:c:func:`!PyMonitoring_EnterScope` should be called whenever the lexical scope is
156156
entered. Scopes can be reentered, reusing the same *state_array* and *version*,
157157
in situations like when emulating a recursive Python function. When a code-like's
158158
execution is paused, such as when emulating a generator, the scope needs to
159159
be exited and re-entered.
160160
161-
162-
.. :c:function:: int PyMonitoring_ExitScope(void)
163-
164-
Exit the last scope that was entered with ``PyMonitoring_EnterScope``.
161+
The macros for *event_types* are:
162+
163+
.. c:namespace:: NULL
164+
165+
.. The table is here to make the docs searchable, and to allow automatic
166+
links to the identifiers.
167+
168+
================================================== =====================================
169+
Macro Event
170+
================================================== =====================================
171+
.. c:macro:: PY_MONITORING_EVENT_BRANCH :monitoring-event:`BRANCH`
172+
.. c:macro:: PY_MONITORING_EVENT_CALL :monitoring-event:`CALL`
173+
.. c:macro:: PY_MONITORING_EVENT_C_RAISE :monitoring-event:`C_RAISE`
174+
.. c:macro:: PY_MONITORING_EVENT_C_RETURN :monitoring-event:`C_RETURN`
175+
.. c:macro:: PY_MONITORING_EVENT_EXCEPTION_HANDLED :monitoring-event:`EXCEPTION_HANDLED`
176+
.. c:macro:: PY_MONITORING_EVENT_INSTRUCTION :monitoring-event:`INSTRUCTION`
177+
.. c:macro:: PY_MONITORING_EVENT_JUMP :monitoring-event:`JUMP`
178+
.. c:macro:: PY_MONITORING_EVENT_LINE :monitoring-event:`LINE`
179+
.. c:macro:: PY_MONITORING_EVENT_PY_RESUME :monitoring-event:`PY_RESUME`
180+
.. c:macro:: PY_MONITORING_EVENT_PY_RETURN :monitoring-event:`PY_RETURN`
181+
.. c:macro:: PY_MONITORING_EVENT_PY_START :monitoring-event:`PY_START`
182+
.. c:macro:: PY_MONITORING_EVENT_PY_THROW :monitoring-event:`PY_THROW`
183+
.. c:macro:: PY_MONITORING_EVENT_PY_UNWIND :monitoring-event:`PY_UNWIND`
184+
.. c:macro:: PY_MONITORING_EVENT_PY_YIELD :monitoring-event:`PY_YIELD`
185+
.. c:macro:: PY_MONITORING_EVENT_RAISE :monitoring-event:`RAISE`
186+
.. c:macro:: PY_MONITORING_EVENT_RERAISE :monitoring-event:`RERAISE`
187+
.. c:macro:: PY_MONITORING_EVENT_STOP_ITERATION :monitoring-event:`STOP_ITERATION`
188+
================================================== =====================================
189+
190+
.. c:function:: int PyMonitoring_ExitScope(void)
191+
192+
Exit the last scope that was entered with :c:func:`!PyMonitoring_EnterScope`.

Doc/c-api/time.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.. highlight:: c
22

3+
.. _c-api-time:
4+
35
PyTime C API
46
============
57

Doc/c-api/type.rst

Lines changed: 67 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,24 @@ Type Objects
264264
265265
.. versionadded:: 3.11
266266
267+
.. c:function:: int PyType_GetBaseByToken(PyTypeObject *type, void *token, PyTypeObject **result)
268+
269+
Find the first superclass in *type*'s :term:`method resolution order` whose
270+
:c:macro:`Py_tp_token` token is equal to the given one.
271+
272+
* If found, set *\*result* to a new :term:`strong reference`
273+
to it and return ``1``.
274+
* If not found, set *\*result* to ``NULL`` and return ``0``.
275+
* On error, set *\*result* to ``NULL`` and return ``-1`` with an
276+
exception set.
277+
278+
The *result* argument may be ``NULL``, in which case *\*result* is not set.
279+
Use this if you need only the return value.
280+
281+
The *token* argument may not be ``NULL``.
282+
283+
.. versionadded:: 3.14
284+
267285
.. c:function:: int PyUnstable_Type_AssignVersionTag(PyTypeObject *type)
268286
269287
Attempt to assign a version tag to the given type.
@@ -488,6 +506,11 @@ The following functions and structs are used to create
488506
* ``Py_nb_add`` to set :c:member:`PyNumberMethods.nb_add`
489507
* ``Py_sq_length`` to set :c:member:`PySequenceMethods.sq_length`
490508
509+
An additional slot is supported that does not correspond to a
510+
:c:type:`!PyTypeObject` struct field:
511+
512+
* :c:data:`Py_tp_token`
513+
491514
The following “offset” fields cannot be set using :c:type:`PyType_Slot`:
492515
493516
* :c:member:`~PyTypeObject.tp_weaklistoffset`
@@ -538,4 +561,47 @@ The following functions and structs are used to create
538561
The desired value of the slot. In most cases, this is a pointer
539562
to a function.
540563
541-
Slots other than ``Py_tp_doc`` may not be ``NULL``.
564+
*pfunc* values may not be ``NULL``, except for the following slots:
565+
566+
* ``Py_tp_doc``
567+
* :c:data:`Py_tp_token` (for clarity, prefer :c:data:`Py_TP_USE_SPEC`
568+
rather than ``NULL``)
569+
570+
.. c:macro:: Py_tp_token
571+
572+
A :c:member:`~PyType_Slot.slot` that records a static memory layout ID
573+
for a class.
574+
575+
If the :c:type:`PyType_Spec` of the class is statically
576+
allocated, the token can be set to the spec using the special value
577+
:c:data:`Py_TP_USE_SPEC`:
578+
579+
.. code-block:: c
580+
581+
static PyType_Slot foo_slots[] = {
582+
{Py_tp_token, Py_TP_USE_SPEC},
583+
584+
It can also be set to an arbitrary pointer, but you must ensure that:
585+
586+
* The pointer outlives the class, so it's not reused for something else
587+
while the class exists.
588+
* It "belongs" to the extension module where the class lives, so it will not
589+
clash with other extensions.
590+
591+
Use :c:func:`PyType_GetBaseByToken` to check if a class's superclass has
592+
a given token -- that is, check whether the memory layout is compatible.
593+
594+
To get the token for a given class (without considering superclasses),
595+
use :c:func:`PyType_GetSlot` with ``Py_tp_token``.
596+
597+
.. versionadded:: 3.14
598+
599+
.. c:namespace:: NULL
600+
601+
.. c:macro:: Py_TP_USE_SPEC
602+
603+
Used as a value with :c:data:`Py_tp_token` to set the token to the
604+
class's :c:type:`PyType_Spec`.
605+
Expands to ``NULL``.
606+
607+
.. versionadded:: 3.14

0 commit comments

Comments
 (0)