Skip to content

Commit bb16973

Browse files
committed
Merge remote-tracking branch 'upstream/main' into codegen-labels-cont
2 parents cf4740b + 325ae93 commit bb16973

File tree

128 files changed

+2267
-2551
lines changed

Some content is hidden

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

128 files changed

+2267
-2551
lines changed

Doc/c-api/call.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,15 @@ This bears repeating:
5757
A class supporting vectorcall **must** also implement
5858
:c:member:`~PyTypeObject.tp_call` with the same semantics.
5959

60+
.. versionchanged:: 3.12
61+
62+
The :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag is now removed from a class
63+
when the class's :py:meth:`~object.__call__` method is reassigned.
64+
(This internally sets :c:member:`~PyTypeObject.tp_call` only, and thus
65+
may make it behave differently than the vectorcall function.)
66+
In earlier Python versions, vectorcall should only be used with
67+
:const:`immutable <Py_TPFLAGS_IMMUTABLETYPE>` or static types.
68+
6069
A class should not implement vectorcall if that would be slower
6170
than *tp_call*. For example, if the callee needs to convert
6271
the arguments to an args tuple and kwargs dict anyway, then there is no point

Doc/c-api/object.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,14 @@ Object Protocol
126126
A generic implementation for the getter of a ``__dict__`` descriptor. It
127127
creates the dictionary if necessary.
128128
129+
This function may also be called to get the :py:attr:`~object.__dict__`
130+
of the object *o*. Pass ``NULL`` for *context* when calling it.
131+
Since this function may need to allocate memory for the
132+
dictionary, it may be more efficient to call :c:func:`PyObject_GetAttr`
133+
when accessing an attribute on the object.
134+
135+
On failure, returns ``NULL`` with an exception set.
136+
129137
.. versionadded:: 3.3
130138
131139
@@ -137,6 +145,16 @@ Object Protocol
137145
.. versionadded:: 3.3
138146
139147
148+
.. c:function:: PyObject** _PyObject_GetDictPtr(PyObject *obj)
149+
150+
Return a pointer to :py:attr:`~object.__dict__` of the object *obj*.
151+
If there is no ``__dict__``, return ``NULL`` without setting an exception.
152+
153+
This function may need to allocate memory for the
154+
dictionary, so it may be more efficient to call :c:func:`PyObject_GetAttr`
155+
when accessing an attribute on the object.
156+
157+
140158
.. c:function:: PyObject* PyObject_RichCompare(PyObject *o1, PyObject *o2, int opid)
141159
142160
Compare the values of *o1* and *o2* using the operation specified by *opid*,

Doc/c-api/typeobj.rst

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ Quick Reference
135135
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
136136
| [:c:member:`~PyTypeObject.tp_cache`] | :c:type:`PyObject` * | | | | |
137137
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
138-
| [:c:member:`~PyTypeObject.tp_subclasses`] | :c:type:`PyObject` * | __subclasses__ | | | |
138+
| [:c:member:`~PyTypeObject.tp_subclasses`] | void * | __subclasses__ | | | |
139139
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
140140
| [:c:member:`~PyTypeObject.tp_weaklist`] | :c:type:`PyObject` * | | | | |
141141
+------------------------------------------------+-----------------------------------+-------------------+---+---+---+---+
@@ -720,29 +720,29 @@ and :c:type:`PyType_Type` effectively act as defaults.)
720720
with the *vectorcallfunc* function.
721721
This can be done by setting *tp_call* to :c:func:`PyVectorcall_Call`.
722722

723-
.. warning::
724-
725-
It is not recommended for :ref:`mutable heap types <heap-types>` to implement
726-
the vectorcall protocol.
727-
When a user sets :attr:`__call__` in Python code, only *tp_call* is updated,
728-
likely making it inconsistent with the vectorcall function.
729-
730723
.. versionchanged:: 3.8
731724

732725
Before version 3.8, this slot was named ``tp_print``.
733726
In Python 2.x, it was used for printing to a file.
734727
In Python 3.0 to 3.7, it was unused.
735728

729+
.. versionchanged:: 3.12
730+
731+
Before version 3.12, it was not recommended for
732+
:ref:`mutable heap types <heap-types>` to implement the vectorcall
733+
protocol.
734+
When a user sets :attr:`~type.__call__` in Python code, only *tp_call* is
735+
updated, likely making it inconsistent with the vectorcall function.
736+
Since 3.12, setting ``__call__`` will disable vectorcall optimization
737+
by clearing the :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag.
738+
736739
**Inheritance:**
737740

738741
This field is always inherited.
739742
However, the :const:`Py_TPFLAGS_HAVE_VECTORCALL` flag is not
740-
always inherited. If it's not, then the subclass won't use
743+
always inherited. If it's not set, then the subclass won't use
741744
:ref:`vectorcall <vectorcall>`, except when
742745
:c:func:`PyVectorcall_Call` is explicitly called.
743-
This is in particular the case for types without the
744-
:const:`Py_TPFLAGS_IMMUTABLETYPE` flag set (including subclasses defined in
745-
Python).
746746

747747

748748
.. c:member:: getattrfunc PyTypeObject.tp_getattr
@@ -1178,12 +1178,18 @@ and :c:type:`PyType_Type` effectively act as defaults.)
11781178

11791179
**Inheritance:**
11801180

1181-
This bit is inherited for types with the
1182-
:const:`Py_TPFLAGS_IMMUTABLETYPE` flag set, if
1183-
:c:member:`~PyTypeObject.tp_call` is also inherited.
1181+
This bit is inherited if :c:member:`~PyTypeObject.tp_call` is also
1182+
inherited.
11841183

11851184
.. versionadded:: 3.9
11861185

1186+
.. versionchanged:: 3.12
1187+
1188+
This flag is now removed from a class when the class's
1189+
:py:meth:`~object.__call__` method is reassigned.
1190+
1191+
This flag can now be inherited by mutable classes.
1192+
11871193
.. data:: Py_TPFLAGS_IMMUTABLETYPE
11881194

11891195
This bit is set for type objects that are immutable: type attributes cannot be set nor deleted.
@@ -1709,18 +1715,11 @@ and :c:type:`PyType_Type` effectively act as defaults.)
17091715
:c:member:`~PyTypeObject.tp_dictoffset` should be set to ``-4`` to indicate that the dictionary is
17101716
at the very end of the structure.
17111717

1712-
The real dictionary offset in an instance can be computed from a negative
1713-
:c:member:`~PyTypeObject.tp_dictoffset` as follows::
1714-
1715-
dictoffset = tp_basicsize + abs(ob_size)*tp_itemsize + tp_dictoffset
1716-
if dictoffset is not aligned on sizeof(void*):
1717-
round up to sizeof(void*)
1718-
1719-
where :c:member:`~PyTypeObject.tp_basicsize`, :c:member:`~PyTypeObject.tp_itemsize` and :c:member:`~PyTypeObject.tp_dictoffset` are
1720-
taken from the type object, and :attr:`ob_size` is taken from the instance. The
1721-
absolute value is taken because ints use the sign of :attr:`ob_size` to
1722-
store the sign of the number. (There's never a need to do this calculation
1723-
yourself; it is done for you by :c:func:`_PyObject_GetDictPtr`.)
1718+
The :c:member:`~PyTypeObject.tp_dictoffset` should be regarded as write-only.
1719+
To get the pointer to the dictionary call :c:func:`PyObject_GenericGetDict`.
1720+
Calling :c:func:`PyObject_GenericGetDict` may need to allocate memory for the
1721+
dictionary, so it is may be more efficient to call :c:func:`PyObject_GetAttr`
1722+
when accessing an attribute on the object.
17241723

17251724
**Inheritance:**
17261725

@@ -1928,9 +1927,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
19281927
This field is not inherited.
19291928

19301929

1931-
.. c:member:: PyObject* PyTypeObject.tp_subclasses
1930+
.. c:member:: void* PyTypeObject.tp_subclasses
1931+
1932+
A collection of subclasses. Internal use only. May be an invalid pointer.
1933+
1934+
To get a list of subclasses, call the Python method
1935+
:py:meth:`~class.__subclasses__`.
1936+
1937+
.. versionchanged:: 3.12
19321938

1933-
List of weak references to subclasses. Internal use only.
1939+
For some types, this field does not hold a valid :c:expr:`PyObject*`.
1940+
The type was changed to :c:expr:`void*` to indicate this.
19341941

19351942
**Inheritance:**
19361943

Doc/c-api/unicode.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -477,9 +477,6 @@ APIs:
477477
| | | :c:func:`PyObject_Repr`. |
478478
+-------------------+---------------------+----------------------------------+
479479
480-
An unrecognized format character causes all the rest of the format string to be
481-
copied as-is to the result string, and any extra arguments discarded.
482-
483480
.. note::
484481
The width formatter unit is number of characters rather than bytes.
485482
The precision formatter unit is number of bytes for ``"%s"`` and
@@ -500,6 +497,11 @@ APIs:
500497
Support width and precision formatter for ``"%s"``, ``"%A"``, ``"%U"``,
501498
``"%V"``, ``"%S"``, ``"%R"`` added.
502499
500+
.. versionchanged:: 3.12
501+
An unrecognized format character now sets a :exc:`SystemError`.
502+
In previous versions it caused all the rest of the format string to be
503+
copied as-is to the result string, and any extra arguments discarded.
504+
503505
504506
.. c:function:: PyObject* PyUnicode_FromFormatV(const char *format, va_list vargs)
505507

Doc/data/stable_abi.dat

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/library/asyncio-eventloop.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ Creating Futures and Tasks
332332

333333
.. method:: loop.create_task(coro, *, name=None, context=None)
334334

335-
Schedule the execution of a :ref:`coroutine`.
335+
Schedule the execution of :ref:`coroutine <coroutine>` *coro*.
336336
Return a :class:`Task` object.
337337

338338
Third-party event loops can use their own subclass of :class:`Task`

Doc/library/bisect.rst

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,16 @@
1313

1414
This module provides support for maintaining a list in sorted order without
1515
having to sort the list after each insertion. For long lists of items with
16-
expensive comparison operations, this can be an improvement over the more common
17-
approach. The module is called :mod:`bisect` because it uses a basic bisection
18-
algorithm to do its work. The source code may be most useful as a working
19-
example of the algorithm (the boundary conditions are already right!).
16+
expensive comparison operations, this can be an improvement over
17+
linear searches or frequent resorting.
18+
19+
The module is called :mod:`bisect` because it uses a basic bisection
20+
algorithm to do its work. Unlike other bisection tools that search for a
21+
specific value, the functions in this module are designed to locate an
22+
insertion point. Accordingly, the functions never call an :meth:`__eq__`
23+
method to determine whether a value has been found. Instead, the
24+
functions only call the :meth:`__lt__` method and will return an insertion
25+
point between values in an array.
2026

2127
The following functions are provided:
2228

@@ -30,16 +36,17 @@ The following functions are provided:
3036
any existing entries. The return value is suitable for use as the first
3137
parameter to ``list.insert()`` assuming that *a* is already sorted.
3238

33-
The returned insertion point *i* partitions the array *a* into two halves so
34-
that ``all(val < x for val in a[lo : i])`` for the left side and
35-
``all(val >= x for val in a[i : hi])`` for the right side.
39+
The returned insertion point *ip* partitions the array *a* into two
40+
slices such that ``all(elem < x for elem in a[lo : ip])`` is true for the
41+
left slice and ``all(elem >= x for elem in a[ip : hi])`` is true for the
42+
right slice.
3643

3744
*key* specifies a :term:`key function` of one argument that is used to
3845
extract a comparison key from each element in the array. To support
3946
searching complex records, the key function is not applied to the *x* value.
4047

41-
If *key* is ``None``, the elements are compared directly with no
42-
intervening function call.
48+
If *key* is ``None``, the elements are compared directly and
49+
no key function is called.
4350

4451
.. versionchanged:: 3.10
4552
Added the *key* parameter.
@@ -51,16 +58,9 @@ The following functions are provided:
5158
Similar to :func:`bisect_left`, but returns an insertion point which comes
5259
after (to the right of) any existing entries of *x* in *a*.
5360

54-
The returned insertion point *i* partitions the array *a* into two halves so
55-
that ``all(val <= x for val in a[lo : i])`` for the left side and
56-
``all(val > x for val in a[i : hi])`` for the right side.
57-
58-
*key* specifies a :term:`key function` of one argument that is used to
59-
extract a comparison key from each element in the array. To support
60-
searching complex records, the key function is not applied to the *x* value.
61-
62-
If *key* is ``None``, the elements are compared directly with no
63-
intervening function call.
61+
The returned insertion point *ip* partitions the array *a* into two slices
62+
such that ``all(elem <= x for elem in a[lo : ip])`` is true for the left slice and
63+
``all(elem > x for elem in a[ip : hi])`` is true for the right slice.
6464

6565
.. versionchanged:: 3.10
6666
Added the *key* parameter.

Doc/library/dis.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,24 @@ The Python compiler currently generates the following bytecode instructions.
408408
.. versionadded:: 3.11
409409

410410

411+
.. opcode:: CACHE
412+
413+
Rather than being an actual instruction, this opcode is used to mark extra
414+
space for the interpreter to cache useful data directly in the bytecode
415+
itself. It is automatically hidden by all ``dis`` utilities, but can be
416+
viewed with ``show_caches=True``.
417+
418+
Logically, this space is part of the preceding instruction. Many opcodes
419+
expect to be followed by an exact number of caches, and will instruct the
420+
interpreter to skip over them at runtime.
421+
422+
Populated caches can look like arbitrary instructions, so great care should
423+
be taken when reading or modifying raw, adaptive bytecode containing
424+
quickened data.
425+
426+
.. versionadded:: 3.11
427+
428+
411429
**Unary operations**
412430

413431
Unary operations take the top of the stack, apply the operation, and push the

Doc/library/email.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,3 @@ Legacy API:
147147
Module :mod:`mailbox`
148148
Tools for creating, reading, and managing collections of messages on disk
149149
using a variety standard formats.
150-
151-
Module :mod:`smtpd`
152-
SMTP server framework (primarily useful for testing)

Doc/library/functools.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ The :mod:`functools` module defines the following functions:
119119
tool for programs being converted from Python 2 which supported the use of
120120
comparison functions.
121121

122-
A comparison function is any callable that accept two arguments, compares them,
122+
A comparison function is any callable that accepts two arguments, compares them,
123123
and returns a negative number for less-than, zero for equality, or a positive
124124
number for greater-than. A key function is a callable that accepts one
125125
argument and returns another value to be used as the sort key.

0 commit comments

Comments
 (0)