Skip to content

Commit 52cef36

Browse files
authored
Merge branch 'main' into fix-issue-135447
2 parents 265a88a + 1953713 commit 52cef36

File tree

335 files changed

+7524
-4341
lines changed

Some content is hidden

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

335 files changed

+7524
-4341
lines changed

.github/workflows/jit.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ on:
55
- '**jit**'
66
- 'Python/bytecodes.c'
77
- 'Python/optimizer*.c'
8+
- 'Python/executor_cases.c.h'
9+
- 'Python/optimizer_cases.c.h'
810
- '!Python/perf_jit_trampoline.c'
911
- '!**/*.md'
1012
- '!**/*.ini'
@@ -13,6 +15,8 @@ on:
1315
- '**jit**'
1416
- 'Python/bytecodes.c'
1517
- 'Python/optimizer*.c'
18+
- 'Python/executor_cases.c.h'
19+
- 'Python/optimizer_cases.c.h'
1620
- '!Python/perf_jit_trampoline.c'
1721
- '!**/*.md'
1822
- '!**/*.ini'

.github/workflows/posix-deps-apt.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,10 @@ apt-get -yq install \
2525
uuid-dev \
2626
xvfb \
2727
zlib1g-dev
28+
29+
# Workaround missing libmpdec-dev on ubuntu 24.04:
30+
# https://launchpad.net/~ondrej/+archive/ubuntu/php
31+
# https://deb.sury.org/
32+
sudo add-apt-repository ppa:ondrej/php
33+
apt-get update
34+
apt-get -yq install libmpdec-dev

.pre-commit-config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ repos:
3434
name: Run Black on Tools/jit/
3535
files: ^Tools/jit/
3636

37+
- repo: https://github.com/Lucas-C/pre-commit-hooks
38+
rev: v1.5.5
39+
hooks:
40+
- id: remove-tabs
41+
types: [python]
42+
exclude: ^Tools/c-analyzer/cpython/_parser.py
43+
3744
- repo: https://github.com/pre-commit/pre-commit-hooks
3845
rev: v5.0.0
3946
hooks:

Doc/c-api/arg.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -686,6 +686,12 @@ Building values
686686
``p`` (:class:`bool`) [int]
687687
Convert a C :c:expr:`int` to a Python :class:`bool` object.
688688
689+
Be aware that this format requires an ``int`` argument.
690+
Unlike most other contexts in C, variadic arguments are not coerced to
691+
a suitable type automatically.
692+
You can convert another type (for example, a pointer or a float) to a
693+
suitable ``int`` value using ``(x) ? 1 : 0`` or ``!!x``.
694+
689695
.. versionadded:: 3.14
690696
691697
``c`` (:class:`bytes` of length 1) [char]

Doc/c-api/capsule.rst

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,19 @@ Refer to :ref:`using-capsules` for more information on using these objects.
105105
``module.attribute``. The *name* stored in the capsule must match this
106106
string exactly.
107107
108+
This function splits *name* on the ``.`` character, and imports the first
109+
element. It then processes further elements using attribute lookups.
110+
108111
Return the capsule's internal *pointer* on success. On failure, set an
109112
exception and return ``NULL``.
110113
114+
.. note::
115+
116+
If *name* points to an attribute of some submodule or subpackage, this
117+
submodule or subpackage must be previously imported using other means
118+
(for example, by using :c:func:`PyImport_ImportModule`) for the
119+
attribute lookups to succeed.
120+
111121
.. versionchanged:: 3.3
112122
*no_block* has no effect anymore.
113123

Doc/c-api/function.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,13 @@ There are a few functions specific to Python functions.
9595
9696
.. versionadded:: 3.12
9797
98+
99+
.. c:function:: PyObject* PyFunction_GetKwDefaults(PyObject *op)
100+
101+
Return the keyword-only argument default values of the function object *op*. This can be a
102+
dictionary of arguments or ``NULL``.
103+
104+
98105
.. c:function:: PyObject* PyFunction_GetClosure(PyObject *op)
99106
100107
Return the closure associated with the function object *op*. This can be ``NULL``
@@ -123,6 +130,19 @@ There are a few functions specific to Python functions.
123130
Raises :exc:`SystemError` and returns ``-1`` on failure.
124131
125132
133+
.. c:function:: PyObject *PyFunction_GET_CODE(PyObject *op)
134+
PyObject *PyFunction_GET_GLOBALS(PyObject *op)
135+
PyObject *PyFunction_GET_MODULE(PyObject *op)
136+
PyObject *PyFunction_GET_DEFAULTS(PyObject *op)
137+
PyObject *PyFunction_GET_KW_DEFAULTS(PyObject *op)
138+
PyObject *PyFunction_GET_CLOSURE(PyObject *op)
139+
PyObject *PyFunction_GET_ANNOTATIONS(PyObject *op)
140+
141+
These functions are similar to their ``PyFunction_Get*`` counterparts, but
142+
do not do type checking. Passing anything other than an instance of
143+
:c:data:`PyFunction_Type` is undefined behavior.
144+
145+
126146
.. c:function:: int PyFunction_AddWatcher(PyFunction_WatchCallback callback)
127147
128148
Register *callback* as a function watcher for the current interpreter.

Doc/c-api/init.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1250,7 +1250,7 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
12501250
.. c:function:: void PyInterpreterState_Clear(PyInterpreterState *interp)
12511251
12521252
Reset all information in an interpreter state object. There must be
1253-
an :term:`attached thread state` for the the interpreter.
1253+
an :term:`attached thread state` for the interpreter.
12541254
12551255
.. audit-event:: cpython.PyInterpreterState_Clear "" c.PyInterpreterState_Clear
12561256
@@ -2277,6 +2277,18 @@ The C-API provides a basic mutual exclusion lock.
22772277
22782278
.. versionadded:: 3.13
22792279
2280+
.. c:function:: int PyMutex_IsLocked(PyMutex *m)
2281+
2282+
Returns non-zero if the mutex *m* is currently locked, zero otherwise.
2283+
2284+
.. note::
2285+
2286+
This function is intended for use in assertions and debugging only and
2287+
should not be used to make concurrency control decisions, as the lock
2288+
state may change immediately after the check.
2289+
2290+
.. versionadded:: next
2291+
22802292
.. _python-critical-section-api:
22812293
22822294
Python Critical Section API

Doc/c-api/long.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
439439
All *n_bytes* of the buffer are written: large buffers are padded with
440440
zeroes.
441441
442-
If the returned value is greater than than *n_bytes*, the value was
442+
If the returned value is greater than *n_bytes*, the value was
443443
truncated: as many of the lowest bits of the value as could fit are written,
444444
and the higher bits are ignored. This matches the typical behavior
445445
of a C-style downcast.

Doc/c-api/object.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ Object Protocol
197197
in favour of using :c:func:`PyObject_DelAttr`, but there are currently no
198198
plans to remove it.
199199
200+
The function must not be called with ``NULL`` *v* and an an exception set.
201+
This case can arise from forgetting ``NULL`` checks and would delete the
202+
attribute.
203+
204+
.. versionchanged:: next
205+
Must not be called with NULL value if an exception is set.
206+
200207
201208
.. c:function:: int PyObject_SetAttrString(PyObject *o, const char *attr_name, PyObject *v)
202209
@@ -207,6 +214,10 @@ Object Protocol
207214
If *v* is ``NULL``, the attribute is deleted, but this feature is
208215
deprecated in favour of using :c:func:`PyObject_DelAttrString`.
209216
217+
The function must not be called with ``NULL`` *v* and an an exception set.
218+
This case can arise from forgetting ``NULL`` checks and would delete the
219+
attribute.
220+
210221
The number of different attribute names passed to this function
211222
should be kept small, usually by using a statically allocated string
212223
as *attr_name*.
@@ -215,6 +226,10 @@ Object Protocol
215226
For more details, see :c:func:`PyUnicode_InternFromString`, which may be
216227
used internally to create a key object.
217228
229+
.. versionchanged:: next
230+
Must not be called with NULL value if an exception is set.
231+
232+
218233
.. c:function:: int PyObject_GenericSetAttr(PyObject *o, PyObject *name, PyObject *value)
219234
220235
Generic attribute setter and deleter function that is meant

Doc/data/refcounts.dat

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,21 +963,45 @@ PyFunction_Check:PyObject*:o:0:
963963
PyFunction_GetAnnotations:PyObject*::0:
964964
PyFunction_GetAnnotations:PyObject*:op:0:
965965

966+
PyFunction_GET_ANNOTATIONS:PyObject*::0:
967+
PyFunction_GET_ANNOTATIONS:PyObject*:op:0:
968+
966969
PyFunction_GetClosure:PyObject*::0:
967970
PyFunction_GetClosure:PyObject*:op:0:
968971

972+
PyFunction_GET_CLOSURE:PyObject*::0:
973+
PyFunction_GET_CLOSURE:PyObject*:op:0:
974+
969975
PyFunction_GetCode:PyObject*::0:
970976
PyFunction_GetCode:PyObject*:op:0:
971977

978+
PyFunction_GET_CODE:PyObject*::0:
979+
PyFunction_GET_CODE:PyObject*:op:0:
980+
972981
PyFunction_GetDefaults:PyObject*::0:
973982
PyFunction_GetDefaults:PyObject*:op:0:
974983

984+
PyFunction_GET_DEFAULTS:PyObject*::0:
985+
PyFunction_GET_DEFAULTS:PyObject*:op:0:
986+
987+
PyFunction_GetKwDefaults:PyObject*::0:
988+
PyFunction_GetKwDefaults:PyObject*:op:0:
989+
990+
PyFunction_GET_KW_DEFAULTS:PyObject*::0:
991+
PyFunction_GET_KW_DEFAULTS:PyObject*:op:0:
992+
975993
PyFunction_GetGlobals:PyObject*::0:
976994
PyFunction_GetGlobals:PyObject*:op:0:
977995

996+
PyFunction_GET_GLOBALS:PyObject*::0:
997+
PyFunction_GET_GLOBALS:PyObject*:op:0:
998+
978999
PyFunction_GetModule:PyObject*::0:
9791000
PyFunction_GetModule:PyObject*:op:0:
9801001

1002+
PyFunction_GET_MODULE:PyObject*::0:
1003+
PyFunction_GET_MODULE:PyObject*:op:0:
1004+
9811005
PyFunction_New:PyObject*::+1:
9821006
PyFunction_New:PyObject*:code:+1:
9831007
PyFunction_New:PyObject*:globals:+1:

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

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

4-
* The bundled copy of ``libmpdecimal``.
54
* The :c:func:`!PyImport_ImportModuleNoBlock`:
65
Use :c:func:`PyImport_ImportModule` instead.
76
* :c:func:`PyWeakref_GetObject` and :c:func:`PyWeakref_GET_OBJECT`:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Pending removal in Python 3.16
2+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
3+
4+
* The bundled copy of ``libmpdec``.

Doc/deprecations/pending-removal-in-3.15.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ Pending removal in Python 3.15
9797
After eight years in the :mod:`typing` module,
9898
it has yet to be supported by any major type checker.
9999

100+
* :mod:`!sre_compile`, :mod:`!sre_constants` and :mod:`!sre_parse` modules.
101+
100102
* :mod:`wave`:
101103

102104
* The ``getmark()``, ``setmark()`` and ``getmarkers()`` methods of

Doc/deprecations/pending-removal-in-future.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,6 @@ although there is currently no date scheduled for their removal.
8989
underscore.
9090
(Contributed by Serhiy Storchaka in :gh:`91760`.)
9191

92-
* :mod:`!sre_compile`, :mod:`!sre_constants` and :mod:`!sre_parse` modules.
93-
9492
* :mod:`shutil`: :func:`~shutil.rmtree`'s *onerror* parameter is deprecated in
9593
Python 3.12; use the *onexc* parameter instead.
9694

Doc/extending/newtypes_tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ be an instance of a subclass.
277277
The explicit cast to ``CustomObject *`` above is needed because we defined
278278
``Custom_dealloc`` to take a ``PyObject *`` argument, as the ``tp_dealloc``
279279
function pointer expects to receive a ``PyObject *`` argument.
280-
By assigning to the the ``tp_dealloc`` slot of a type, we declare
280+
By assigning to the ``tp_dealloc`` slot of a type, we declare
281281
that it can only be called with instances of our ``CustomObject``
282282
class, so the cast to ``(CustomObject *)`` is safe.
283283
This is object-oriented polymorphism, in C!

Doc/howto/functional.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ generators:
602602
raise an exception inside the generator; the exception is raised by the
603603
``yield`` expression where the generator's execution is paused.
604604

605-
* :meth:`~generator.close` raises a :exc:`GeneratorExit` exception inside the
605+
* :meth:`~generator.close` sends a :exc:`GeneratorExit` exception to the
606606
generator to terminate the iteration. On receiving this exception, the
607607
generator's code must either raise :exc:`GeneratorExit` or
608608
:exc:`StopIteration`; catching the exception and doing anything else is
@@ -1217,7 +1217,7 @@ flow inside a program. The book uses Scheme for its examples, but many of the
12171217
design approaches described in these chapters are applicable to functional-style
12181218
Python code.
12191219

1220-
https://www.defmacro.org/ramblings/fp.html: A general introduction to functional
1220+
https://defmacro.org/2006/06/19/fp.html: A general introduction to functional
12211221
programming that uses Java examples and has a lengthy historical introduction.
12221222

12231223
https://en.wikipedia.org/wiki/Functional_programming: General Wikipedia entry

Doc/howto/isolating-extensions.rst

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,7 @@ Avoiding ``PyObject_New``
453453

454454
GC-tracked objects need to be allocated using GC-aware functions.
455455

456-
If you use use :c:func:`PyObject_New` or :c:func:`PyObject_NewVar`:
456+
If you use :c:func:`PyObject_New` or :c:func:`PyObject_NewVar`:
457457

458458
- Get and call type's :c:member:`~PyTypeObject.tp_alloc` slot, if possible.
459459
That is, replace ``TYPE *o = PyObject_New(TYPE, typeobj)`` with::
@@ -626,8 +626,7 @@ Open Issues
626626

627627
Several issues around per-module state and heap types are still open.
628628

629-
Discussions about improving the situation are best held on the `capi-sig
630-
mailing list <https://mail.python.org/mailman3/lists/capi-sig.python.org/>`__.
629+
Discussions about improving the situation are best held on the `discuss forum under c-api tag <https://discuss.python.org/c/core-dev/c-api/30>`__.
631630

632631

633632
Per-Class Scope

Doc/installing/index.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ switch::
188188
Once the Development & Deployment part of PPUG is fleshed out, some of
189189
those sections should be linked from new questions here (most notably,
190190
we should have a question about avoiding depending on PyPI that links to
191-
https://packaging.python.org/en/latest/mirrors/)
191+
https://packaging.python.org/en/latest/guides/index-mirrors-and-caches/)
192192
193193
194194
Common installation issues

Doc/library/argparse.rst

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -839,23 +839,11 @@ how the command-line arguments should be handled. The supplied actions are:
839839
>>> parser.parse_args(['--version'])
840840
PROG 2.0
841841

842-
Only actions that consume command-line arguments (e.g. ``'store'``,
843-
``'append'`` or ``'extend'``) can be used with positional arguments.
844-
845-
.. class:: BooleanOptionalAction
846-
847-
You may also specify an arbitrary action by passing an :class:`Action` subclass or
848-
other object that implements the same interface. The :class:`!BooleanOptionalAction`
849-
is available in :mod:`!argparse` and adds support for boolean actions such as
850-
``--foo`` and ``--no-foo``::
851-
852-
>>> import argparse
853-
>>> parser = argparse.ArgumentParser()
854-
>>> parser.add_argument('--foo', action=argparse.BooleanOptionalAction)
855-
>>> parser.parse_args(['--no-foo'])
856-
Namespace(foo=False)
857-
858-
.. versionadded:: 3.9
842+
You may also specify an arbitrary action by passing an :class:`Action` subclass
843+
(e.g. :class:`BooleanOptionalAction`) or other object that implements the same
844+
interface. Only actions that consume command-line arguments (e.g. ``'store'``,
845+
``'append'``, ``'extend'``, or custom actions with non-zero ``nargs``) can be used
846+
with positional arguments.
859847

860848
The recommended way to create a custom action is to extend :class:`Action`,
861849
overriding the :meth:`!__call__` method and optionally the :meth:`!__init__` and
@@ -955,7 +943,7 @@ See also :ref:`specifying-ambiguous-arguments`. The supported values are:
955943

956944
.. index:: single: + (plus); in argparse module
957945

958-
* ``'+'``. Just like ``'*'``, all command-line args present are gathered into a
946+
* ``'+'``. Just like ``'*'``, all command-line arguments present are gathered into a
959947
list. Additionally, an error message will be generated if there wasn't at
960948
least one command-line argument present. For example::
961949

@@ -1429,6 +1417,21 @@ this API may be passed as the ``action`` parameter to
14291417
and return a string which will be used when printing the usage of the program.
14301418
If such method is not provided, a sensible default will be used.
14311419

1420+
.. class:: BooleanOptionalAction
1421+
1422+
A subclass of :class:`Action` for handling boolean flags with positive
1423+
and negative options. Adding a single argument such as ``--foo`` automatically
1424+
creates both ``--foo`` and ``--no-foo`` options, storing ``True`` and ``False``
1425+
respectively::
1426+
1427+
>>> import argparse
1428+
>>> parser = argparse.ArgumentParser()
1429+
>>> parser.add_argument('--foo', action=argparse.BooleanOptionalAction)
1430+
>>> parser.parse_args(['--no-foo'])
1431+
Namespace(foo=False)
1432+
1433+
.. versionadded:: 3.9
1434+
14321435

14331436
The parse_args() method
14341437
-----------------------

Doc/library/codecs.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,14 @@ any codec:
5353
:exc:`UnicodeDecodeError`). Refer to :ref:`codec-base-classes` for more
5454
information on codec error handling.
5555

56+
.. function:: charmap_build(string)
57+
58+
Return a mapping suitable for encoding with a custom single-byte encoding.
59+
Given a :class:`str` *string* of up to 256 characters representing a
60+
decoding table, returns either a compact internal mapping object
61+
``EncodingMap`` or a :class:`dictionary <dict>` mapping character ordinals
62+
to byte values. Raises a :exc:`TypeError` on invalid input.
63+
5664
The full details for each codec can also be looked up directly:
5765

5866
.. function:: lookup(encoding, /)

0 commit comments

Comments
 (0)