Skip to content

Commit 1f697e6

Browse files
committed
Merge branch 'main' into pth2toml
2 parents f05e9f6 + 9e1f164 commit 1f697e6

69 files changed

Lines changed: 633 additions & 198 deletions

Some content is hidden

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

.github/workflows/reusable-emscripten.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
build-emscripten-reusable:
1111
name: 'build and test'
1212
runs-on: ubuntu-24.04
13-
timeout-minutes: 60
13+
timeout-minutes: 40
1414
steps:
1515
- uses: actions/checkout@v6
1616
with:

Doc/c-api/descriptor.rst

Lines changed: 79 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,31 @@ Descriptor Objects
88
"Descriptors" are objects that describe some attribute of an object. They are
99
found in the dictionary of type objects.
1010

11-
.. XXX document these!
12-
1311
.. c:function:: PyObject* PyDescr_NewGetSet(PyTypeObject *type, struct PyGetSetDef *getset)
1412
13+
Create a new get-set descriptor for extension type *type* from the
14+
:c:type:`PyGetSetDef` structure *getset*.
15+
16+
Get-set descriptors expose attributes implemented by C getter and setter
17+
functions rather than stored directly in the instance. This is the same kind
18+
of descriptor created for entries in :c:member:`~PyTypeObject.tp_getset`, and
19+
it appears in Python as a :class:`types.GetSetDescriptorType` object.
20+
21+
On success, return a :term:`strong reference` to the descriptor. Return
22+
``NULL`` with an exception set on failure.
23+
24+
.. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *member)
1525
16-
.. c:function:: PyObject* PyDescr_NewMember(PyTypeObject *type, struct PyMemberDef *meth)
26+
Create a new member descriptor for extension type *type* from the
27+
:c:type:`PyMemberDef` structure *member*.
1728
29+
Member descriptors expose fields in the type's C struct as Python
30+
attributes. This is the same kind of descriptor created for entries in
31+
:c:member:`~PyTypeObject.tp_members`, and it appears in Python as a
32+
:class:`types.MemberDescriptorType` object.
33+
34+
On success, return a :term:`strong reference` to the descriptor. Return
35+
``NULL`` with an exception set on failure.
1836
1937
.. c:var:: PyTypeObject PyMemberDescr_Type
2038
@@ -30,22 +48,53 @@ found in the dictionary of type objects.
3048
The type object for get/set descriptor objects created from
3149
:c:type:`PyGetSetDef` structures. These descriptors implement attributes
3250
whose value is computed by C getter and setter functions, and are used
33-
for many built-in type attributes.
51+
for many built-in type attributes. They correspond to
52+
:class:`types.GetSetDescriptorType` objects in Python.
3453
3554
3655
.. c:function:: PyObject* PyDescr_NewMethod(PyTypeObject *type, struct PyMethodDef *meth)
3756
57+
Create a new method descriptor for extension type *type* from the
58+
:c:type:`PyMethodDef` structure *meth*.
59+
60+
Method descriptors expose C functions as methods on a type. This is the same
61+
kind of descriptor created for entries in
62+
:c:member:`~PyTypeObject.tp_methods`, and it appears in Python as a
63+
:class:`types.MethodDescriptorType` object.
64+
65+
On success, return a :term:`strong reference` to the descriptor. Return
66+
``NULL`` with an exception set on failure.
3867
3968
.. c:var:: PyTypeObject PyMethodDescr_Type
4069
4170
The type object for method descriptor objects created from
4271
:c:type:`PyMethodDef` structures. These descriptors expose C functions as
43-
methods on a type, and correspond to :class:`types.MemberDescriptorType`
72+
methods on a type, and correspond to :class:`types.MethodDescriptorType`
4473
objects in Python.
4574
4675
47-
.. c:function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *wrapper, void *wrapped)
76+
.. c:struct:: wrapperbase
77+
78+
Describes a slot wrapper used by :c:func:`PyDescr_NewWrapper`.
4879
80+
Each ``wrapperbase`` record stores the Python-visible name and metadata for a
81+
special method implemented by a type slot, together with the wrapper
82+
function used to adapt that slot to Python's calling convention.
83+
84+
.. c:function:: PyObject* PyDescr_NewWrapper(PyTypeObject *type, struct wrapperbase *base, void *wrapped)
85+
86+
Create a new wrapper descriptor for extension type *type* from the
87+
:c:struct:`wrapperbase` structure *base* and the wrapped slot function
88+
pointer
89+
*wrapped*.
90+
91+
Wrapper descriptors expose special methods implemented by type slots. This
92+
is the same kind of descriptor that CPython creates for slot-based special
93+
methods such as ``__repr__`` or ``__add__``, and it appears in Python as a
94+
:class:`types.WrapperDescriptorType` object.
95+
96+
On success, return a :term:`strong reference` to the descriptor. Return
97+
``NULL`` with an exception set on failure.
4998
5099
.. c:var:: PyTypeObject PyWrapperDescr_Type
51100
@@ -58,6 +107,16 @@ found in the dictionary of type objects.
58107
59108
.. c:function:: PyObject* PyDescr_NewClassMethod(PyTypeObject *type, PyMethodDef *method)
60109
110+
Create a new class method descriptor for extension type *type* from the
111+
:c:type:`PyMethodDef` structure *method*.
112+
113+
Class method descriptors expose C methods that receive the class rather than
114+
an instance when accessed. This is the same kind of descriptor created for
115+
``METH_CLASS`` entries in :c:member:`~PyTypeObject.tp_methods`, and it
116+
appears in Python as a :class:`types.ClassMethodDescriptorType` object.
117+
118+
On success, return a :term:`strong reference` to the descriptor. Return
119+
``NULL`` with an exception set on failure.
61120
62121
.. c:function:: int PyDescr_IsData(PyObject *descr)
63122
@@ -66,8 +125,18 @@ found in the dictionary of type objects.
66125
no error checking.
67126
68127
69-
.. c:function:: PyObject* PyWrapper_New(PyObject *, PyObject *)
128+
.. c:function:: PyObject* PyWrapper_New(PyObject *d, PyObject *self)
129+
130+
Create a new bound wrapper object from the wrapper descriptor *d* and the
131+
instance *self*.
132+
133+
This is the bound form of a wrapper descriptor created by
134+
:c:func:`PyDescr_NewWrapper`. CPython creates these objects when a slot
135+
wrapper is accessed through an instance, and they appear in Python as
136+
:class:`types.MethodWrapperType` objects.
70137
138+
On success, return a :term:`strong reference` to the wrapper object. Return
139+
``NULL`` with an exception set on failure.
71140
72141
.. c:macro:: PyDescr_COMMON
73142
@@ -104,9 +173,9 @@ Built-in descriptors
104173
.. c:var:: PyTypeObject PyClassMethodDescr_Type
105174
106175
The type object for C-level class method descriptor objects.
107-
This is the type of the descriptors created for :func:`classmethod` defined in
108-
C extension types, and is the same object as :class:`classmethod`
109-
in Python.
176+
This is the type of the descriptors created for :func:`classmethod` defined
177+
in C extension types, and corresponds to
178+
:class:`types.ClassMethodDescriptorType` objects in Python.
110179
111180
112181
.. c:function:: PyObject *PyClassMethod_New(PyObject *callable)

Doc/data/threadsafety.dat

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,4 +123,33 @@ PyByteArray_GET_SIZE:atomic:
123123

124124
# Raw data - no locking; mutating it is unsafe if the bytearray object is shared between threads
125125
PyByteArray_AsString:compatible:
126-
PyByteArray_AS_STRING:compatible:
126+
PyByteArray_AS_STRING:compatible:
127+
128+
# Capsule objects (Doc/c-api/capsule.rst)
129+
130+
# Type check - read ob_type pointer, always safe
131+
PyCapsule_CheckExact:atomic:
132+
133+
# Creation - pure allocation, no shared state
134+
PyCapsule_New:atomic:
135+
136+
# Validation - reads pointer and name fields; safe on distinct objects
137+
PyCapsule_IsValid:distinct:
138+
139+
# Getters - read struct fields; safe on distinct objects but
140+
# concurrent access to the same capsule requires external synchronization
141+
PyCapsule_GetPointer:distinct:
142+
PyCapsule_GetName:distinct:
143+
PyCapsule_GetDestructor:distinct:
144+
PyCapsule_GetContext:distinct:
145+
146+
# Setters - write struct fields; safe on distinct objects but
147+
# concurrent access to the same capsule requires external synchronization
148+
PyCapsule_SetPointer:distinct:
149+
PyCapsule_SetName:distinct:
150+
PyCapsule_SetDestructor:distinct:
151+
PyCapsule_SetContext:distinct:
152+
153+
# Import - looks up a capsule from a module attribute and
154+
# calls PyCapsule_GetPointer; may call arbitrary code
155+
PyCapsule_Import:compatible:

Doc/library/array.rst

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,15 @@ defined:
4242
+-----------+--------------------+-------------------+-----------------------+-------+
4343
| ``'Q'`` | unsigned long long | int | 8 | |
4444
+-----------+--------------------+-------------------+-----------------------+-------+
45+
| ``'e'`` | _Float16 | float | 2 | \(3) |
46+
+-----------+--------------------+-------------------+-----------------------+-------+
4547
| ``'f'`` | float | float | 4 | |
4648
+-----------+--------------------+-------------------+-----------------------+-------+
4749
| ``'d'`` | double | float | 8 | |
4850
+-----------+--------------------+-------------------+-----------------------+-------+
49-
| ``'F'`` | float complex | complex | 8 | \(3) |
51+
| ``'F'`` | float complex | complex | 8 | \(4) |
5052
+-----------+--------------------+-------------------+-----------------------+-------+
51-
| ``'D'`` | double complex | complex | 16 | \(3) |
53+
| ``'D'`` | double complex | complex | 16 | \(4) |
5254
+-----------+--------------------+-------------------+-----------------------+-------+
5355

5456

@@ -69,6 +71,15 @@ Notes:
6971
.. versionadded:: 3.13
7072

7173
(3)
74+
The IEEE 754 binary16 "half precision" type was introduced in the 2008
75+
revision of the `IEEE 754 standard <ieee 754 standard_>`_.
76+
This type is not widely supported by C compilers. It's available
77+
as :c:expr:`_Float16` type, if the compiler supports the Annex H
78+
of the C23 standard.
79+
80+
.. versionadded:: next
81+
82+
(4)
7283
Complex types (``F`` and ``D``) are available unconditionally,
7384
regardless on support for complex types (the Annex G of the C11 standard)
7485
by the C compiler.
@@ -304,3 +315,5 @@ Examples::
304315

305316
`NumPy <https://numpy.org/>`_
306317
The NumPy package defines another array type.
318+
319+
.. _ieee 754 standard: https://en.wikipedia.org/wiki/IEEE_754-2008_revision

Doc/library/plistlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ and XML plist files.
1818

1919
The property list (``.plist``) file format is a simple serialization supporting
2020
basic object types, like dictionaries, lists, numbers and strings. Usually the
21-
top level object is a dictionary.
21+
top level object is a dictionary or a frozen dictionary.
2222

2323
To write out and to parse a plist file, use the :func:`dump` and
2424
:func:`load` functions.

Doc/library/stdtypes.rst

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3735,12 +3735,13 @@ arbitrary binary data.
37353735
The separator to search for may be any :term:`bytes-like object`.
37363736

37373737

3738-
.. method:: bytes.replace(old, new, count=-1, /)
3739-
bytearray.replace(old, new, count=-1, /)
3738+
.. method:: bytes.replace(old, new, /, count=-1)
3739+
bytearray.replace(old, new, /, count=-1)
37403740

37413741
Return a copy of the sequence with all occurrences of subsequence *old*
3742-
replaced by *new*. If the optional argument *count* is given, only the
3743-
first *count* occurrences are replaced.
3742+
replaced by *new*. If *count* is given, only the first *count* occurrences
3743+
are replaced. If *count* is not specified or ``-1``, then all occurrences
3744+
are replaced.
37443745

37453746
The subsequence to search for and its replacement may be any
37463747
:term:`bytes-like object`.
@@ -3750,6 +3751,9 @@ arbitrary binary data.
37503751
The bytearray version of this method does *not* operate in place - it
37513752
always produces a new object, even if no changes were made.
37523753

3754+
.. versionchanged:: next
3755+
*count* is now supported as a keyword argument.
3756+
37533757

37543758
.. method:: bytes.rfind(sub[, start[, end]])
37553759
bytearray.rfind(sub[, start[, end]])

Doc/library/xml.etree.elementtree.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -691,7 +691,7 @@ Functions
691691
.. versionadded:: 3.2
692692

693693

694-
.. function:: SubElement(parent, tag, attrib={}, **extra)
694+
.. function:: SubElement(parent, tag, /, attrib={}, **extra)
695695

696696
Subelement factory. This function creates an element instance, and appends
697697
it to an existing element.
@@ -705,6 +705,9 @@ Functions
705705
.. versionchanged:: 3.15
706706
*attrib* can now be a :class:`frozendict`.
707707

708+
.. versionchanged:: next
709+
*parent* and *tag* are now positional-only parameters.
710+
708711

709712
.. function:: tostring(element, encoding="us-ascii", method="xml", *, \
710713
xml_declaration=None, default_namespace=None, \
@@ -880,7 +883,7 @@ Element Objects
880883
:noindex:
881884
:no-index:
882885

883-
.. class:: Element(tag, attrib={}, **extra)
886+
.. class:: Element(tag, /, attrib={}, **extra)
884887

885888
Element class. This class defines the Element interface, and provides a
886889
reference implementation of this interface.
@@ -893,6 +896,9 @@ Element Objects
893896
.. versionchanged:: 3.15
894897
*attrib* can now be a :class:`frozendict`.
895898

899+
.. versionchanged:: next
900+
*tag* is now a positional-only parameter.
901+
896902

897903
.. attribute:: tag
898904

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
# as tested on the CI via check-warnings.py in reusable-docs.yml.
33
# Keep lines sorted lexicographically to help avoid merge conflicts.
44

5-
Doc/c-api/descriptor.rst
65
Doc/c-api/init_config.rst
76
Doc/c-api/intro.rst
87
Doc/c-api/stable.rst

Doc/whatsnew/3.15.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,8 @@ For example::
217217

218218
The following standard library modules have been updated to accept
219219
:class:`!frozendict`: :mod:`copy`, :mod:`decimal`, :mod:`json`, :mod:`marshal`,
220-
:mod:`pickle`, :mod:`pprint` and :mod:`xml.etree.ElementTree`.
220+
:mod:`plistlib` (only for serialization), :mod:`pickle`, :mod:`pprint` and
221+
:mod:`xml.etree.ElementTree`.
221222

222223
:func:`eval` and :func:`exec` accept :class:`!frozendict` for *globals*, and
223224
:func:`type` and :meth:`str.maketrans` accept :class:`!frozendict` for *dict*.
@@ -604,6 +605,9 @@ Other language changes
604605
respectively.
605606
(Contributed by Sergey B Kirpichev in :gh:`146151`.)
606607

608+
* Allow the *count* argument of :meth:`bytes.replace` to be a keyword.
609+
(Contributed by Stan Ulbrych in :gh:`147856`.)
610+
607611

608612
New modules
609613
===========
@@ -642,6 +646,10 @@ array
642646
formatting characters ``'F'`` and ``'D'`` respectively.
643647
(Contributed by Sergey B Kirpichev in :gh:`146151`.)
644648

649+
* Support half-floats (16-bit IEEE 754 binary interchange format): formatting
650+
character ``'e'``.
651+
(Contributed by Sergey B Kirpichev in :gh:`146238`.)
652+
645653

646654
base64
647655
------

Include/internal/pycore_long.h

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,20 @@ _PyLong_IsPositive(const PyLongObject *op)
232232
return (op->long_value.lv_tag & SIGN_MASK) == 0;
233233
}
234234

235+
/* Return true if the argument is a small int */
236+
static inline bool
237+
_PyLong_IsSmallInt(const PyLongObject *op)
238+
{
239+
assert(PyLong_Check(op));
240+
bool is_small_int = (op->long_value.lv_tag & IMMORTALITY_BIT_MASK) != 0;
241+
assert(PyLong_CheckExact(op) || (!is_small_int));
242+
assert(_Py_IsImmortal(op) || (!is_small_int));
243+
assert((_PyLong_IsCompact(op)
244+
&& _PY_IS_SMALL_INT(_PyLong_CompactValue(op)))
245+
|| (!is_small_int));
246+
return is_small_int;
247+
}
248+
235249
static inline Py_ssize_t
236250
_PyLong_DigitCount(const PyLongObject *op)
237251
{
@@ -293,7 +307,9 @@ _PyLong_SetDigitCount(PyLongObject *op, Py_ssize_t size)
293307
#define NON_SIZE_MASK ~(uintptr_t)((1 << NON_SIZE_BITS) - 1)
294308

295309
static inline void
296-
_PyLong_FlipSign(PyLongObject *op) {
310+
_PyLong_FlipSign(PyLongObject *op)
311+
{
312+
assert(!_PyLong_IsSmallInt(op));
297313
unsigned int flipped_sign = 2 - (op->long_value.lv_tag & SIGN_MASK);
298314
op->long_value.lv_tag &= NON_SIZE_MASK;
299315
op->long_value.lv_tag |= flipped_sign;

0 commit comments

Comments
 (0)