Skip to content

Commit 738507d

Browse files
committed
Merge branch 'main' into issue-46771
2 parents 6fb9cfc + 7fce106 commit 738507d

File tree

121 files changed

+1563
-1400
lines changed

Some content is hidden

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

121 files changed

+1563
-1400
lines changed

.github/workflows/doc.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
- name: 'Build HTML documentation'
4949
run: make -C Doc/ PYTHON=../python SPHINXOPTS="-q -W --keep-going -j4" html
5050
- name: 'Upload'
51-
uses: actions/upload-artifact@v2.2.4
51+
uses: actions/upload-artifact@v2.3.1
5252
with:
5353
name: doc-html
5454
path: Doc/build/html

Doc/c-api/exceptions.rst

+8-7
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,14 @@ For convenience, some of these functions will always return a
253253
.. versionadded:: 3.3
254254
255255
256+
.. c:function:: PyObject* PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg, PyObject *name, PyObject *path)
257+
258+
Much like :c:func:`PyErr_SetImportError` but this function allows for
259+
specifying a subclass of :exc:`ImportError` to raise.
260+
261+
.. versionadded:: 3.6
262+
263+
256264
.. c:function:: void PyErr_SyntaxLocationObject(PyObject *filename, int lineno, int col_offset)
257265
258266
Set file, line, and offset information for the current exception. If the
@@ -320,13 +328,6 @@ an error value).
320328
:mod:`warnings` module and the :option:`-W` option in the command line
321329
documentation. There is no C API for warning control.
322330
323-
.. c:function:: PyObject* PyErr_SetImportErrorSubclass(PyObject *exception, PyObject *msg, PyObject *name, PyObject *path)
324-
325-
Much like :c:func:`PyErr_SetImportError` but this function allows for
326-
specifying a subclass of :exc:`ImportError` to raise.
327-
328-
.. versionadded:: 3.6
329-
330331
331332
.. c:function:: int PyErr_WarnExplicitObject(PyObject *category, PyObject *message, PyObject *filename, int lineno, PyObject *module, PyObject *registry)
332333

Doc/c-api/reflection.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ Reflection
3131
See also :c:func:`PyThreadState_GetFrame`.
3232
3333
34-
.. c:function:: int PyFrame_GetBack(PyFrameObject *frame)
34+
.. c:function:: PyFrameObject* PyFrame_GetBack(PyFrameObject *frame)
3535
3636
Get the *frame* next outer frame.
3737
@@ -42,7 +42,7 @@ Reflection
4242
.. versionadded:: 3.9
4343
4444
45-
.. c:function:: int PyFrame_GetCode(PyFrameObject *frame)
45+
.. c:function:: PyCodeObject* PyFrame_GetCode(PyFrameObject *frame)
4646
4747
Get the *frame* code.
4848

Doc/c-api/typeobj.rst

+14-13
Original file line numberDiff line numberDiff line change
@@ -476,7 +476,7 @@ PyObject Slots
476476
--------------
477477

478478
The type object structure extends the :c:type:`PyVarObject` structure. The
479-
:attr:`ob_size` field is used for dynamic types (created by :func:`type_new`,
479+
:attr:`ob_size` field is used for dynamic types (created by :func:`type_new`,
480480
usually called from a class statement). Note that :c:data:`PyType_Type` (the
481481
metatype) initializes :c:member:`~PyTypeObject.tp_itemsize`, which means that its instances (i.e.
482482
type objects) *must* have the :attr:`ob_size` field.
@@ -2000,6 +2000,17 @@ and :c:type:`PyType_Type` effectively act as defaults.)
20002000
For this field to be taken into account (even through inheritance),
20012001
you must also set the :const:`Py_TPFLAGS_HAVE_FINALIZE` flags bit.
20022002

2003+
Also, note that, in a garbage collected Python,
2004+
:c:member:`~PyTypeObject.tp_dealloc` may be called from
2005+
any Python thread, not just the thread which created the object (if the object
2006+
becomes part of a refcount cycle, that cycle might be collected by a garbage
2007+
collection on any thread). This is not a problem for Python API calls, since
2008+
the thread on which tp_dealloc is called will own the Global Interpreter Lock
2009+
(GIL). However, if the object being destroyed in turn destroys objects from some
2010+
other C or C++ library, care should be taken to ensure that destroying those
2011+
objects on the thread which called tp_dealloc will not violate any assumptions
2012+
of the library.
2013+
20032014
**Inheritance:**
20042015

20052016
This field is inherited by subtypes.
@@ -2024,17 +2035,6 @@ and :c:type:`PyType_Type` effectively act as defaults.)
20242035
.. versionadded:: 3.9 (the field exists since 3.8 but it's only used since 3.9)
20252036

20262037

2027-
Also, note that, in a garbage collected Python, :c:member:`~PyTypeObject.tp_dealloc` may be called from
2028-
any Python thread, not just the thread which created the object (if the object
2029-
becomes part of a refcount cycle, that cycle might be collected by a garbage
2030-
collection on any thread). This is not a problem for Python API calls, since
2031-
the thread on which tp_dealloc is called will own the Global Interpreter Lock
2032-
(GIL). However, if the object being destroyed in turn destroys objects from some
2033-
other C or C++ library, care should be taken to ensure that destroying those
2034-
objects on the thread which called tp_dealloc will not violate any assumptions
2035-
of the library.
2036-
2037-
20382038
.. _static-types:
20392039

20402040
Static Types
@@ -2440,7 +2440,8 @@ Async Object Structures
24402440

24412441
PyObject *am_aiter(PyObject *self);
24422442

2443-
Must return an :term:`awaitable` object. See :meth:`__anext__` for details.
2443+
Must return an :term:`asynchronous iterator` object.
2444+
See :meth:`__anext__` for details.
24442445

24452446
This slot may be set to ``NULL`` if an object does not implement
24462447
asynchronous iteration protocol.

Doc/c-api/unicode.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ Error handling is set by errors which may also be set to ``NULL`` meaning to use
10031003
the default handling defined for the codec. Default error handling for all
10041004
built-in codecs is "strict" (:exc:`ValueError` is raised).
10051005
1006-
The codecs all use a similar interface. Only deviation from the following
1006+
The codecs all use a similar interface. Only deviations from the following
10071007
generic ones are documented for simplicity.
10081008
10091009
@@ -1171,7 +1171,7 @@ These are the UTF-16 codec APIs:
11711171
``1``, any byte order mark is copied to the output (where it will result in
11721172
either a ``\ufeff`` or a ``\ufffe`` character).
11731173
1174-
After completion, *\*byteorder* is set to the current byte order at the end
1174+
After completion, ``*byteorder`` is set to the current byte order at the end
11751175
of input data.
11761176
11771177
If *byteorder* is ``NULL``, the codec starts in native order mode.
@@ -1302,7 +1302,7 @@ Character Map Codecs
13021302
13031303
This codec is special in that it can be used to implement many different codecs
13041304
(and this is in fact what was done to obtain most of the standard codecs
1305-
included in the :mod:`encodings` package). The codec uses mapping to encode and
1305+
included in the :mod:`encodings` package). The codec uses mappings to encode and
13061306
decode characters. The mapping objects provided must support the
13071307
:meth:`__getitem__` mapping interface; dictionaries and sequences work well.
13081308
@@ -1426,7 +1426,7 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
14261426
.. c:function:: PyObject* PyUnicode_Splitlines(PyObject *s, int keepend)
14271427
14281428
Split a Unicode string at line breaks, returning a list of Unicode strings.
1429-
CRLF is considered to be one line break. If *keepend* is ``0``, the Line break
1429+
CRLF is considered to be one line break. If *keepend* is ``0``, the line break
14301430
characters are not included in the resulting strings.
14311431
14321432

Doc/c-api/veryhigh.rst

+2
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,8 @@ the same library that the Python runtime is using.
7575
:c:func:`PyRun_SimpleFile`. *filename* is decoded from the filesystem
7676
encoding (:func:`sys.getfilesystemencoding`). If *filename* is ``NULL``, this
7777
function uses ``"???"`` as the filename.
78+
If *closeit* is true, the file is closed before
79+
``PyRun_SimpleFileExFlags()`` returns.
7880
7981
8082
.. c:function:: int PyRun_SimpleString(const char *command)

Doc/library/asyncio-task.rst

+3
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,9 @@ Task Object
843843
.. versionchanged:: 3.9
844844
Added the *msg* parameter.
845845

846+
.. versionchanged:: 3.11
847+
The ``msg`` parameter is propagated from cancelled task to its awaiter.
848+
846849
.. _asyncio_example_task_cancel:
847850

848851
The following example illustrates how coroutines can intercept

Doc/library/configparser.rst

+3
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,9 @@ out. Values can also span multiple lines, as long as they are indented deeper
267267
than the first line of the value. Depending on the parser's mode, blank lines
268268
may be treated as parts of multiline values or ignored.
269269

270+
By default, a valid section name can be any string that does not contain '\\n' or ']'.
271+
To change this, see :attr:`ConfigParser.SECTCRE`.
272+
270273
Configuration files may include comments, prefixed by specific
271274
characters (``#`` and ``;`` by default [1]_). Comments may appear on
272275
their own on an otherwise empty line, possibly indented. [1]_

Doc/library/dis.rst

+34-21
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ the following command can be used to display the disassembly of
3636
>>> dis.dis(myfunc)
3737
1 0 RESUME 0
3838

39-
2 2 LOAD_GLOBAL 0 (len)
40-
4 LOAD_FAST 0 (alist)
41-
6 PRECALL_FUNCTION 1
42-
8 CALL 0
43-
10 RETURN_VALUE
39+
2 2 PUSH_NULL
40+
4 LOAD_GLOBAL 0 (len)
41+
6 LOAD_FAST 0 (alist)
42+
8 PRECALL 1
43+
10 CALL 1
44+
12 RETURN_VALUE
4445

4546
(The "2" is a line number).
4647

@@ -106,9 +107,10 @@ Example::
106107
... print(instr.opname)
107108
...
108109
RESUME
110+
PUSH_NULL
109111
LOAD_GLOBAL
110112
LOAD_FAST
111-
PRECALL_FUNCTION
113+
PRECALL
112114
CALL
113115
RETURN_VALUE
114116

@@ -1063,18 +1065,28 @@ iterations of the loop.
10631065
with ``__cause__`` set to ``TOS``)
10641066

10651067

1066-
.. opcode:: CALL (named)
1068+
.. opcode:: CALL (argc)
10671069

1068-
Calls a callable object with the number of positional arguments specified by
1069-
the preceding :opcode:`PRECALL_FUNCTION` or :opcode:`PRECALL_METHOD` and
1070-
the named arguments specified by the preceding :opcode:`KW_NAMES`, if any.
1071-
*named* indicates the number of named arguments.
1072-
On the stack are (in ascending order):
1070+
Calls a callable object with the number of arguments specified by ``argc``,
1071+
including the named arguments specified by the preceding
1072+
:opcode:`KW_NAMES`, if any.
1073+
On the stack are (in ascending order), either:
10731074

1075+
* NULL
10741076
* The callable
10751077
* The positional arguments
10761078
* The named arguments
10771079

1080+
or:
1081+
1082+
* The callable
1083+
* ``self``
1084+
* The remaining positional arguments
1085+
* The named arguments
1086+
1087+
``argc`` is the total of the positional and named arguments, excluding
1088+
``self`` when a ``NULL`` is not present.
1089+
10781090
``CALL`` pops all arguments and the callable object off the stack,
10791091
calls the callable object with those arguments, and pushes the return value
10801092
returned by the callable object.
@@ -1102,33 +1114,34 @@ iterations of the loop.
11021114
Loads a method named ``co_names[namei]`` from the TOS object. TOS is popped.
11031115
This bytecode distinguishes two cases: if TOS has a method with the correct
11041116
name, the bytecode pushes the unbound method and TOS. TOS will be used as
1105-
the first argument (``self``) by :opcode:`PRECALL_METHOD` when calling the
1117+
the first argument (``self``) by :opcode:`CALL` when calling the
11061118
unbound method. Otherwise, ``NULL`` and the object return by the attribute
11071119
lookup are pushed.
11081120

11091121
.. versionadded:: 3.7
11101122

11111123

1112-
.. opcode:: PRECALL_METHOD (argc)
1124+
.. opcode:: PRECALL (argc)
11131125

1114-
Prefixes :opcode:`CALL` (possibly with an intervening ``KW_NAMES``).
1115-
This opcode is designed to be used with :opcode:`LOAD_METHOD`.
1116-
Sets internal variables, so that :opcode:`CALL`
1117-
clean up after :opcode:`LOAD_METHOD` correctly.
1126+
Prefixes :opcode:`CALL`. Logically this is a no op.
1127+
It exists to enable effective specialization of calls.
1128+
``argc`` is the number of arguments as described in :opcode:`CALL`.
11181129

11191130
.. versionadded:: 3.11
11201131

11211132

1122-
.. opcode:: PRECALL_FUNCTION (args)
1133+
.. opcode:: PUSH_NULL
11231134

1124-
Prefixes :opcode:`CALL` (possibly with an intervening ``KW_NAMES``).
1125-
Sets internal variables, so that :opcode:`CALL` can execute correctly.
1135+
Pushes a ``NULL`` to the stack.
1136+
Used in the call sequence to match the ``NULL`` pushed by
1137+
:opcode:`LOAD_METHOD` for non-method calls.
11261138

11271139
.. versionadded:: 3.11
11281140

11291141

11301142
.. opcode:: KW_NAMES (i)
11311143

1144+
Prefixes :opcode:`PRECALL`.
11321145
Stores a reference to ``co_consts[consti]`` into an internal variable
11331146
for use by :opcode:`CALL`. ``co_consts[consti]`` must be a tuple of strings.
11341147

Doc/library/locale.rst

+2
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,8 @@ The :mod:`locale` module defines the following exception and functions:
301301
*language code* and *encoding* may be ``None`` if their values cannot be
302302
determined.
303303

304+
.. deprecated:: 3.11 3.13
305+
304306

305307
.. function:: getlocale(category=LC_CTYPE)
306308

Doc/reference/compound_stmts.rst

+13-8
Original file line numberDiff line numberDiff line change
@@ -154,17 +154,20 @@ The :keyword:`for` statement is used to iterate over the elements of a sequence
154154
(such as a string, tuple or list) or other iterable object:
155155

156156
.. productionlist:: python-grammar
157-
for_stmt: "for" `target_list` "in" `expression_list` ":" `suite`
157+
for_stmt: "for" `target_list` "in" `starred_list` ":" `suite`
158158
: ["else" ":" `suite`]
159159

160160
The expression list is evaluated once; it should yield an iterable object. An
161-
iterator is created for the result of the ``expression_list``. The suite is
162-
then executed once for each item provided by the iterator, in the order returned
163-
by the iterator. Each item in turn is assigned to the target list using the
164-
standard rules for assignments (see :ref:`assignment`), and then the suite is
165-
executed. When the items are exhausted (which is immediately when the sequence
166-
is empty or an iterator raises a :exc:`StopIteration` exception), the suite in
167-
the :keyword:`!else` clause, if present, is executed, and the loop terminates.
161+
iterator is created for the result of the ``starred_list``. The expression
162+
list can contain starred elements (``*x, *y``) that will be unpacked in the
163+
final iterator (as when constructing a ``tuple`` or ``list`` literal). The
164+
suite is then executed once for each item provided by the iterator, in the
165+
order returned by the iterator. Each item in turn is assigned to the target
166+
list using the standard rules for assignments (see :ref:`assignment`), and then
167+
the suite is executed. When the items are exhausted (which is immediately when
168+
the sequence is empty or an iterator raises a :exc:`StopIteration` exception),
169+
the suite in the :keyword:`!else` clause, if present, is executed, and the loop
170+
terminates.
168171

169172
.. index::
170173
statement: break
@@ -196,6 +199,8 @@ the built-in function :func:`range` returns an iterator of integers suitable to
196199
emulate the effect of Pascal's ``for i := a to b do``; e.g., ``list(range(3))``
197200
returns the list ``[0, 1, 2]``.
198201

202+
.. versionchanged:: 3.11
203+
Starred elements are now allowed in the expression list.
199204

200205
.. _try:
201206
.. _except:

Doc/using/windows.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ suppressing the UI in order to change some of the defaults.
129129
To completely hide the installer UI and install Python silently, pass the
130130
``/quiet`` option. To skip past the user interaction but still display
131131
progress and errors, pass the ``/passive`` option. The ``/uninstall``
132-
option may be passed to immediately begin removing Python - no prompt will be
133-
displayed.
132+
option may be passed to immediately begin removing Python - no confirmation
133+
prompt will be displayed.
134134

135135
All other options are passed as ``name=value``, where the value is usually
136136
``0`` to disable a feature, ``1`` to enable a feature, or a path. The full list

Doc/whatsnew/3.11.rst

+15
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,9 @@ traceback. (Contributed by Irit Katriel in :issue:`45607`.)
160160
Other Language Changes
161161
======================
162162

163+
* Starred expressions can be used in :ref:`for statements<for>`. (See
164+
:issue:`46725` for more details.)
165+
163166
* Asynchronous comprehensions are now allowed inside comprehensions in
164167
asynchronous functions. Outer comprehensions implicitly become
165168
asynchronous. (Contributed by Serhiy Storchaka in :issue:`33346`.)
@@ -483,6 +486,12 @@ Deprecated
483486

484487
(Contributed by Hugo van Kemenade in :issue:`45173`.)
485488

489+
* The :func:`locale.getdefaultlocale` function is deprecated and will be
490+
removed in Python 3.13. Use :func:`locale.setlocale`,
491+
:func:`locale.getpreferredencoding(False) <locale.getpreferredencoding>` and
492+
:func:`locale.getlocale` functions instead.
493+
(Contributed by Victor Stinner in :issue:`46659`.)
494+
486495

487496
Removed
488497
=======
@@ -844,6 +853,8 @@ Porting to Python 3.11
844853
use ``PyObject_GetAttrString((PyObject*)frame, "f_locals")``.
845854
* ``f_lasti``: removed,
846855
use ``PyObject_GetAttrString((PyObject*)frame, "f_lasti")``.
856+
Code using ``f_lasti`` with ``PyCode_Addr2Line()`` should use
857+
:c:func:`PyFrame_GetLineNumber` instead.
847858

848859
The following fields were removed entirely, as they were details
849860
of the old implementation:
@@ -1010,3 +1021,7 @@ Removed
10101021
public C API by mistake, it must only be used by Python internally.
10111022
Use the ``PyTypeObject.tp_members`` member instead.
10121023
(Contributed by Victor Stinner in :issue:`40170`.)
1024+
1025+
* Remove the ``HAVE_PY_SET_53BIT_PRECISION`` macro (moved to the internal C
1026+
API).
1027+
(Contributed by Victor Stinner in :issue:`45412`.)

Include/Python.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
#include "pymacro.h"
4040
#include "pymath.h"
4141
#include "pymem.h"
42+
#include "pybuffer.h"
4243
#include "object.h"
4344
#include "objimpl.h"
4445
#include "typeslots.h"
@@ -50,7 +51,6 @@
5051
#include "longobject.h"
5152
#include "cpython/longintrepr.h"
5253
#include "boolobject.h"
53-
#include "buffer.h"
5454
#include "floatobject.h"
5555
#include "complexobject.h"
5656
#include "rangeobject.h"

0 commit comments

Comments
 (0)