Skip to content

Commit d887293

Browse files
Merge remote-tracking branch 'upstream/main' into specialize_overridden
2 parents c6f8610 + 32ac98e commit d887293

File tree

696 files changed

+28806
-13080
lines changed

Some content is hidden

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

696 files changed

+28806
-13080
lines changed

.gitattributes

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ Lib/test/cjkencodings/* noeol
2828
Lib/test/coding20731.py noeol
2929
Lib/test/decimaltestdata/*.decTest noeol
3030
Lib/test/test_email/data/*.txt noeol
31-
Lib/test/test_importlib/data01/* noeol
32-
Lib/test/test_importlib/namespacedata01/* noeol
31+
Lib/test/test_importlib/resources/data01/* noeol
32+
Lib/test/test_importlib/resources/namespacedata01/* noeol
3333
Lib/test/xmltestdata/* noeol
3434

3535
# CRLF files

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ Python/pythonrun.c @iritkatriel
6161
# bytecode.
6262
**/*import*.c @brettcannon @encukou @ericsnowcurrently @ncoghlan @warsaw
6363
**/*import*.py @brettcannon @encukou @ericsnowcurrently @ncoghlan @warsaw
64-
**/importlib/resources/* @jaraco @warsaw @brettcannon
64+
**/*importlib/resources/* @jaraco @warsaw @brettcannon
6565
**/importlib/metadata/* @jaraco @warsaw
6666

6767
# Dates and times

.github/CONTRIBUTING.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,19 @@ Build Status
66

77
- main
88

9-
+ `Stable buildbots <http://buildbot.python.org/3.x.stable/>`_
9+
+ `Stable buildbots <https://buildbot.python.org/3.x.stable/>`_
1010

1111
- 3.9
1212

13-
+ `Stable buildbots <http://buildbot.python.org/3.9.stable/>`_
13+
+ `Stable buildbots <https://buildbot.python.org/3.9.stable/>`_
1414

1515
- 3.8
1616

17-
+ `Stable buildbots <http://buildbot.python.org/3.8.stable/>`_
17+
+ `Stable buildbots <https://buildbot.python.org/3.8.stable/>`_
1818

1919
- 3.7
2020

21-
+ `Stable buildbots <http://buildbot.python.org/3.7.stable/>`_
21+
+ `Stable buildbots <https://buildbot.python.org/3.7.stable/>`_
2222

2323

2424
Thank You

.github/ISSUE_TEMPLATE/bug.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@ labels: "type-bug"
1515
your problem has already been reported
1616
-->
1717

18-
**Bug report**
18+
# Bug report
1919

2020
A clear and concise description of what the bug is.
2121
Include a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example), if possible.
2222

23-
**Your environment**
23+
# Your environment
2424

2525
<!-- Include as many relevant details as possible about the environment you experienced the bug in -->
2626

.github/ISSUE_TEMPLATE/crash.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ labels: "type-crash"
1313
For CPython, a "crash" is when Python itself fails, leading to a traceback in the C stack.
1414
-->
1515

16-
**Crash report**
16+
# Crash report
1717

1818
Tell us what happened, ideally including a minimal, reproducible example (https://stackoverflow.com/help/minimal-reproducible-example).
1919

20-
**Error messages**
20+
# Error messages
2121

2222
Enter any relevant error message caused by the crash, including a core dump if there is one.
2323

24-
**Your environment**
24+
# Your environment
2525

2626
<!-- Include as many relevant details as possible about the environment you experienced the bug in -->
2727

.github/ISSUE_TEMPLATE/documentation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ about: Report a problem with the documentation
44
labels: "docs"
55
---
66

7-
**Documentation**
7+
# Documentation
88

99
(A clear and concise description of the issue.)

.github/ISSUE_TEMPLATE/feature.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ about: Submit a proposal for a new CPython feature or enhancement
44
labels: "type-feature"
55
---
66

7-
**Feature or enhancement**
7+
# Feature or enhancement
88

99
(A clear and concise description of your proposal.)
1010

11-
**Pitch**
11+
# Pitch
1212

1313
(Explain why this feature or enhancement should be implemented and how it would be used.
1414
Add examples, if applicable.)
1515

16-
**Previous discussion**
16+
# Previous discussion
1717

1818
<!--
1919
New features to Python should first be discussed elsewhere before creating issues on GitHub,

.github/workflows/doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,4 +78,4 @@ jobs:
7878
run: make -C Doc/ PYTHON=../python venv
7979
# Use "xvfb-run" since some doctest tests open GUI windows
8080
- name: 'Run documentation doctest'
81-
run: xvfb-run make -C Doc/ PYTHON=../python SPHINXOPTS="-q" SPHINXERRORHANDLING="-W --keep-going" doctest
81+
run: xvfb-run make -C Doc/ PYTHON=../python SPHINXERRORHANDLING="-W --keep-going" doctest

Doc/about.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ About these documents
66
These documents are generated from `reStructuredText`_ sources by `Sphinx`_, a
77
document processor specifically written for the Python documentation.
88

9-
.. _reStructuredText: http://docutils.sourceforge.net/rst.html
9+
.. _reStructuredText: https://docutils.sourceforge.io/rst.html
1010
.. _Sphinx: http://sphinx-doc.org/
1111

1212
.. In the online version of these documents, you can submit comments and suggest
@@ -21,7 +21,7 @@ Many thanks go to:
2121

2222
* Fred L. Drake, Jr., the creator of the original Python documentation toolset
2323
and writer of much of the content;
24-
* the `Docutils <http://docutils.sourceforge.net/>`_ project for creating
24+
* the `Docutils <https://docutils.sourceforge.io/>`_ project for creating
2525
reStructuredText and the Docutils suite;
2626
* Fredrik Lundh for his Alternative Python Reference project from which Sphinx
2727
got many good ideas.

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/code.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,28 @@ bound into a function.
9090
9191
.. versionadded:: 3.11
9292
93+
.. c:function:: PyObject* PyCode_GetVarnames(PyCodeObject *co)
94+
95+
Equivalent to the Python code ``getattr(co, 'co_varnames')``.
96+
Returns a new reference to a :c:type:`PyTupleObject` containing the names of
97+
the local variables. On error, ``NULL`` is returned and an exception
98+
is raised.
99+
100+
.. versionadded:: 3.11
101+
102+
.. c:function:: PyObject* PyCode_GetCellvars(PyCodeObject *co)
103+
104+
Equivalent to the Python code ``getattr(co, 'co_cellvars')``.
105+
Returns a new reference to a :c:type:`PyTupleObject` containing the names of
106+
the local variables that are referenced by nested functions. On error, ``NULL``
107+
is returned and an exception is raised.
108+
109+
.. versionadded:: 3.11
110+
111+
.. c:function:: PyObject* PyCode_GetFreevars(PyCodeObject *co)
112+
113+
Equivalent to the Python code ``getattr(co, 'co_freevars')``.
114+
Returns a new reference to a :c:type:`PyTupleObject` containing the names of
115+
the free variables. On error, ``NULL`` is returned and an exception is raised.
116+
117+
.. versionadded:: 3.11

Doc/c-api/long.rst

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,15 @@ distinguished from a number. Use :c:func:`PyErr_Occurred` to disambiguate.
8484
.. c:function:: PyObject* PyLong_FromString(const char *str, char **pend, int base)
8585
8686
Return a new :c:type:`PyLongObject` based on the string value in *str*, which
87-
is interpreted according to the radix in *base*. If *pend* is non-``NULL``,
88-
*\*pend* will point to the first character in *str* which follows the
89-
representation of the number. If *base* is ``0``, *str* is interpreted using
90-
the :ref:`integers` definition; in this case, leading zeros in a
91-
non-zero decimal number raises a :exc:`ValueError`. If *base* is not ``0``,
92-
it must be between ``2`` and ``36``, inclusive. Leading spaces and single
93-
underscores after a base specifier and between digits are ignored. If there
94-
are no digits, :exc:`ValueError` will be raised.
87+
is interpreted according to the radix in *base*, or ``NULL`` on failure. If
88+
*pend* is non-``NULL``, *\*pend* will point to the end of *str* on success or
89+
to the first character that could not be processed on error. If *base* is ``0``,
90+
*str* is interpreted using the :ref:`integers` definition; in this case, leading
91+
zeros in a non-zero decimal number raises a :exc:`ValueError`. If *base* is not
92+
``0``, it must be between ``2`` and ``36``, inclusive. Leading and trailing
93+
whitespace and single underscores after a base specifier and between digits are
94+
ignored. If there are no digits or *str* is not NULL-terminated following the
95+
digits and trailing whitespace, :exc:`ValueError` will be raised.
9596
9697
9798
.. c:function:: PyObject* PyLong_FromUnicodeObject(PyObject *u, int base)

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: 43 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__`.
19321936

1933-
List of weak references to subclasses. Internal use only.
1937+
.. versionchanged:: 3.12
1938+
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

@@ -1942,6 +1949,13 @@ and :c:type:`PyType_Type` effectively act as defaults.)
19421949
Weak reference list head, for weak references to this type object. Not
19431950
inherited. Internal use only.
19441951

1952+
.. versionchanged:: 3.12
1953+
1954+
Internals detail: For the static builtin types this is always ``NULL``,
1955+
even if weakrefs are added. Instead, the weakrefs for each are stored
1956+
on ``PyInterpreterState``. Use the public C-API or the internal
1957+
``_PyObject_GET_WEAKREFS_LISTPTR()`` macro to avoid the distinction.
1958+
19451959
**Inheritance:**
19461960

19471961
This field is not inherited.

Doc/c-api/unicode.rst

Lines changed: 6 additions & 4 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
@@ -819,7 +821,7 @@ wchar_t Support
819821
most C functions. If *size* is ``NULL`` and the :c:type:`wchar_t*` string
820822
contains null characters a :exc:`ValueError` is raised.
821823
822-
Returns a buffer allocated by :c:func:`PyMem_Alloc` (use
824+
Returns a buffer allocated by :c:func:`PyMem_New` (use
823825
:c:func:`PyMem_Free` to free it) on success. On error, returns ``NULL``
824826
and *\*size* is undefined. Raises a :exc:`MemoryError` if memory allocation
825827
is failed.

0 commit comments

Comments
 (0)