Skip to content

Commit 12f69ed

Browse files
committed
Merge remote-tracking branch 'upstream/main' into gh-114258-contains
2 parents 65eb4d5 + 5a17b2e commit 12f69ed

72 files changed

Lines changed: 4150 additions & 710 deletions

File tree

Some content is hidden

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

‎Doc/c-api/exceptions.rst‎

Lines changed: 258 additions & 173 deletions
Large diffs are not rendered by default.

‎Doc/c-api/import.rst‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,7 @@ Importing Modules
363363
364364
.. c:function:: int PyImport_SetLazyImportsMode(PyImport_LazyImportsMode mode)
365365
366-
Similar to :c:func:`PyImport_ImportModuleAttr`, but names are UTF-8 encoded
367-
strings instead of Python :class:`str` objects.
366+
Sets the current lazy imports mode.
368367
369368
This function always returns ``0``.
370369

‎Doc/c-api/iterator.rst‎

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -72,23 +72,28 @@ Builtin Iterator Types
7272
These are built-in iteration types that are included in Python's C API, but
7373
provide no additional functions. They are here for completeness.
7474
75-
76-
.. list-table::
77-
:widths: auto
78-
:header-rows: 1
79-
80-
* * C type
81-
* Python type
82-
* * .. c:var:: PyTypeObject PyEnum_Type
83-
* :py:class:`enumerate`
84-
* * .. c:var:: PyTypeObject PyFilter_Type
85-
* :py:class:`filter`
86-
* * .. c:var:: PyTypeObject PyMap_Type
87-
* :py:class:`map`
88-
* * .. c:var:: PyTypeObject PyReversed_Type
89-
* :py:class:`reversed`
90-
* * .. c:var:: PyTypeObject PyZip_Type
91-
* :py:class:`zip`
75+
.. stable-abi-note::
76+
77+
These pointers are part of the :ref:`Stable ABI <stable>`.
78+
79+
.. omit-stable-abi-notes::
80+
81+
.. list-table::
82+
:widths: auto
83+
:header-rows: 1
84+
85+
* * C type
86+
* Python type
87+
* * .. c:var:: PyTypeObject PyEnum_Type
88+
* :py:class:`enumerate`
89+
* * .. c:var:: PyTypeObject PyFilter_Type
90+
* :py:class:`filter`
91+
* * .. c:var:: PyTypeObject PyMap_Type
92+
* :py:class:`map`
93+
* * .. c:var:: PyTypeObject PyReversed_Type
94+
* :py:class:`reversed`
95+
* * .. c:var:: PyTypeObject PyZip_Type
96+
* :py:class:`zip`
9297
9398
9499
Other Iterator Objects

‎Doc/conf.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@
214214
('c:macro', 'LONG_MIN'),
215215
# Standard C variables
216216
('c:data', 'errno'),
217+
# Platform-specific socket constants documented collectively as SO_*.
218+
('py:const', 'socket.SO_EXCLUSIVEADDRUSE'),
219+
('py:const', 'socket.SO_REUSEADDR'),
220+
('py:const', 'socket.SO_REUSEPORT'),
217221
# Standard environment variables
218222
('envvar', 'BROWSER'),
219223
('envvar', 'COLUMNS'),

‎Doc/library/argparse.rst‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1771,8 +1771,9 @@ Subcommands
17711771

17721772
* help_ - help for sub-parser group in help output, by default ``None``
17731773

1774-
* metavar_ - string presenting available subcommands in help; by default it
1775-
is ``None`` and presents subcommands in form {cmd1, cmd2, ..}
1774+
* metavar_ - placeholder shown in usage and the subparsers' help entry
1775+
instead of ``{cmd1, cmd2, ...}``; by default ``None``.
1776+
Individual subcommand names are unchanged.
17761777

17771778
Some example usage::
17781779

‎Doc/library/concurrent.interpreters.rst‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,16 @@ Interpreter objects
244244
Generally, :class:`Interpreter` shouldn't be called directly.
245245
Instead, use :func:`create` or one of the other module functions.
246246

247+
:class:`!Interpreter` objects support the :term:`context manager`
248+
protocol. Exiting the :keyword:`with` block calls :meth:`close`::
249+
250+
with interpreters.create() as interp:
251+
interp.exec('print("hello")')
252+
253+
.. versionchanged:: next
254+
Added support for using :class:`!Interpreter` objects in
255+
a :term:`context manager`.
256+
247257
.. attribute:: id
248258

249259
(read-only)

‎Doc/library/gzip.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ The module defines the following items:
112112
The *compresslevel* argument is an integer from ``0`` to ``9`` controlling
113113
the level of compression; ``1`` is fastest and produces the least
114114
compression, and ``9`` is slowest and produces the most compression. ``0``
115-
is no compression. The default is ``9``.
115+
is no compression. The default is ``6``.
116116

117117
The optional *mtime* argument is the timestamp requested by gzip. The time
118118
is in Unix format, i.e., seconds since 00:00:00 UTC, January 1, 1970. Set

‎Doc/library/sys.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -678,6 +678,11 @@ always available. Unless explicitly noted otherwise, all variables are read-only
678678
- :option:`-X context_aware_warnings <-X>` and
679679
:envvar:`PYTHON_CONTEXT_AWARE_WARNINGS`
680680

681+
* - .. attribute:: flags.lazy_imports
682+
- :option:`-X lazy_imports <-X>` and :envvar:`PYTHON_LAZY_IMPORTS`
683+
(``1`` for ``all``, ``-1`` otherwise; not changed by
684+
:func:`set_lazy_imports`)
685+
681686

682687
.. versionchanged:: 3.2
683688
Added ``quiet`` attribute for the new :option:`-q` flag.
@@ -714,6 +719,9 @@ always available. Unless explicitly noted otherwise, all variables are read-only
714719
.. versionchanged:: 3.14
715720
Added the ``context_aware_warnings`` attribute.
716721

722+
.. versionchanged:: 3.15
723+
Added the ``lazy_imports`` attribute.
724+
717725

718726
.. data:: float_info
719727

‎Doc/library/test.rst‎

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,8 @@ The :mod:`!test.support` module defines the following functions:
506506

507507
.. function:: with_pymalloc()
508508

509-
Return :const:`_testcapi.WITH_PYMALLOC`.
509+
Return ``True`` if Python was built with :ref:`pymalloc <pymalloc>` enabled
510+
and is not a :term:`free-threaded build`.
510511

511512

512513
.. function:: requires(resource, msg=None)
@@ -1088,7 +1089,7 @@ The :mod:`!test.support` module defines the following functions:
10881089

10891090
.. function:: skip_if_broken_multiprocessing_synchronize()
10901091

1091-
Skip tests if the :mod:`multiprocessing.synchronize` module is missing, if
1092+
Skip tests if the :mod:`!multiprocessing.synchronize` module is missing, if
10921093
there is no available semaphore implementation, or if creating a lock raises
10931094
an :exc:`OSError`.
10941095

@@ -1260,7 +1261,7 @@ script execution tests.
12601261
doesn't have an obvious home with Python's current home finding logic.
12611262

12621263
Setting :envvar:`PYTHONHOME` is one way to get most of the testsuite to run
1263-
in that situation. :envvar:`PYTHONPATH` or :envvar:`PYTHONUSERSITE` are
1264+
in that situation. :envvar:`PYTHONPATH` or :envvar:`PYTHONNOUSERSITE` are
12641265
other common environment variables that might impact whether or not the
12651266
interpreter can start.
12661267

@@ -1708,8 +1709,8 @@ The :mod:`!test.support.import_helper` module provides support for import tests.
17081709

17091710
This function imports and returns a fresh copy of the named Python module
17101711
by removing the named module from ``sys.modules`` before doing the import.
1711-
Note that unlike :func:`reload`, the original module is not affected by
1712-
this operation.
1712+
Note that unlike :func:`importlib.reload`, the original module is not
1713+
affected by this operation.
17131714

17141715
*fresh* is an iterable of additional module names that are also removed
17151716
from the ``sys.modules`` cache before doing the import.
@@ -1871,17 +1872,10 @@ The :mod:`!test.support.warnings_helper` module provides support for warnings te
18711872

18721873
In this case all warnings are caught and no errors are raised.
18731874

1874-
On entry to the context manager, a :class:`WarningRecorder` instance is
1875-
returned. The underlying warnings list from
1876-
:func:`~warnings.catch_warnings` is available via the recorder object's
1877-
:attr:`warnings` attribute. As a convenience, the attributes of the object
1878-
representing the most recent warning can also be accessed directly through
1879-
the recorder object (see example below). If no warning has been raised,
1880-
then any of the attributes that would otherwise be expected on an object
1881-
representing a warning will return ``None``.
1882-
1883-
The recorder object also has a :meth:`reset` method, which clears the
1884-
warnings list.
1875+
On entry to the context manager, a :class:`WarningsRecorder` instance is
1876+
returned. The recorded warnings are available via its
1877+
:attr:`~WarningsRecorder.warnings` attribute, and its
1878+
:meth:`~WarningsRecorder.reset` method discards previously recorded warnings.
18851879

18861880
The context manager is designed to be used like this::
18871881

@@ -1898,11 +1892,11 @@ The :mod:`!test.support.warnings_helper` module provides support for warnings te
18981892

18991893
with check_warnings(quiet=True) as w:
19001894
warnings.warn("foo")
1901-
assert str(w.args[0]) == "foo"
1895+
assert str(w.message) == "foo"
19021896
warnings.warn("bar")
1903-
assert str(w.args[0]) == "bar"
1904-
assert str(w.warnings[0].args[0]) == "foo"
1905-
assert str(w.warnings[1].args[0]) == "bar"
1897+
assert str(w.message) == "bar"
1898+
assert str(w.warnings[0].message) == "foo"
1899+
assert str(w.warnings[1].message) == "bar"
19061900
w.reset()
19071901
assert len(w.warnings) == 0
19081902

@@ -1914,7 +1908,22 @@ The :mod:`!test.support.warnings_helper` module provides support for warnings te
19141908
New optional arguments *filters* and *quiet*.
19151909

19161910

1917-
.. class:: WarningsRecorder()
1911+
.. class:: WarningsRecorder(warnings_list)
1912+
1913+
Class used to record warnings for unit tests. Wraps the warnings list
1914+
returned by :func:`warnings.catch_warnings` when recording is enabled.
1915+
:func:`check_warnings` returns an instance of this class.
1916+
1917+
As a convenience, the attributes of the object representing the most recent
1918+
warning can also be accessed directly through the recorder object.
1919+
If no warning has been raised since the recorder was created or last reset,
1920+
these attributes return ``None``.
1921+
1922+
.. attribute:: warnings
1923+
1924+
A list of warnings recorded since the recorder was created or last reset.
1925+
1926+
.. method:: reset()
19181927

1919-
Class used to record warnings for unit tests. See documentation of
1920-
:func:`check_warnings` above for more details.
1928+
Discard previously recorded warnings from the recorder's view.
1929+
The underlying warnings list is not modified.

‎Doc/library/tokenize.rst‎

Lines changed: 74 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ colorizers for on-screen displays.
1515

1616
To simplify token stream handling, all :ref:`operator <operators>` and
1717
:ref:`delimiter <delimiters>` tokens and :data:`Ellipsis` are returned using
18-
the generic :data:`~token.OP` token type. The exact
19-
type can be determined by checking the ``exact_type`` property on the
20-
:term:`named tuple` returned from :func:`tokenize.tokenize`.
18+
the generic :data:`~token.OP` token type.
19+
The :attr:`TokenInfo.exact_type` property gives the exact token type.
2120

2221

2322
.. warning::
@@ -40,25 +39,10 @@ The primary entry point is a :term:`generator`:
4039
:meth:`io.IOBase.readline` method of file objects. Each call to the
4140
function should return one line of input as bytes.
4241

43-
The generator produces 5-tuples with these members: the token type; the
44-
token string; a 2-tuple ``(srow, scol)`` of ints specifying the row and
45-
column where the token begins in the source; a 2-tuple ``(erow, ecol)`` of
46-
ints specifying the row and column where the token ends in the source; and
47-
the line on which the token was found. The line passed (the last tuple item)
48-
is the *physical* line. The 5 tuple is returned as a :term:`named tuple`
49-
with the field names:
50-
``type string start end line``.
51-
52-
The returned :term:`named tuple` has an additional property named
53-
``exact_type`` that contains the exact operator type for
54-
:data:`~token.OP` tokens. For all other token types ``exact_type``
55-
equals the named tuple ``type`` field.
42+
The generator produces :class:`TokenInfo` objects.
5643

5744
.. versionchanged:: 3.1
58-
Added support for named tuples.
59-
60-
.. versionchanged:: 3.3
61-
Added support for ``exact_type``.
45+
Changed to yield :class:`TokenInfo` objects instead of plain tuples.
6246

6347
:func:`.tokenize` determines the source encoding of the file by looking for a
6448
UTF-8 BOM or encoding cookie, according to :pep:`263`.
@@ -71,9 +55,78 @@ The primary entry point is a :term:`generator`:
7155
a single line of input. However, :func:`generate_tokens` expects *readline*
7256
to return a str object rather than bytes.
7357

74-
The result is an iterator yielding named tuples, exactly like
58+
The result is an iterator yielding :class:`TokenInfo` objects, exactly like
7559
:func:`.tokenize`. It does not yield an :data:`~token.ENCODING` token.
7660

61+
.. class:: TokenInfo(type, string, start, end, line)
62+
63+
A :term:`named tuple` describing a token. It has five fields and an
64+
additional :attr:`exact_type` property.
65+
66+
.. versionadded:: 3.1
67+
68+
.. attribute:: type
69+
70+
An integer identifying the token type, as defined by the constants in
71+
:mod:`token`, such as :data:`~token.NAME` and :data:`~token.STRING`.
72+
Operators and delimiters have type :data:`~token.OP`; use
73+
:attr:`exact_type` for their specific token type.
74+
75+
.. attribute:: string
76+
77+
The token text as a :class:`str`.
78+
For :data:`~token.STRING` tokens, this includes the quotes, any prefix,
79+
and escape sequences, without evaluating them.
80+
81+
For an :data:`~token.ENCODING` token, this is the encoding name.
82+
Tokens inserted without corresponding source text can have an empty
83+
string. In :data:`~token.FSTRING_MIDDLE` and
84+
:data:`~token.TSTRING_MIDDLE` tokens, doubled braces are replaced by
85+
single braces.
86+
87+
.. attribute:: start
88+
89+
A 2-tuple ``(srow, scol)`` of ints specifying the inclusive start
90+
position of the token in the source. Rows are numbered from 1 and
91+
columns from 0. Columns count Unicode code points; a tab counts as
92+
one column, without expanding it to a tab stop.
93+
94+
For an :data:`~token.ENCODING` token, this is ``(0, 0)``.
95+
96+
.. attribute:: end
97+
98+
A 2-tuple ``(erow, ecol)`` of ints specifying the exclusive end
99+
position of the token. Rows are numbered from 1 and columns from 0.
100+
For a token spanning multiple lines, *erow* is the final row and
101+
*ecol* is the column on that row.
102+
103+
For example, the name ``spam`` at the beginning of the first line
104+
has :attr:`start` equal to ``(1, 0)`` and :attr:`end` equal to ``(1, 4)``.
105+
106+
For an :data:`~token.ENCODING` token, this is ``(0, 0)``.
107+
A :data:`~token.NEWLINE` or :data:`~token.NL` token inserted at the end
108+
of input without a final newline can have an end column one beyond
109+
the source text.
110+
111+
.. attribute:: line
112+
113+
A :class:`str` containing the full source line on which
114+
the token was found, including surrounding text and the line terminator
115+
if present. For a token spanning multiple lines, this can contain
116+
several source lines. It is empty for :data:`~token.ENCODING` and
117+
:data:`~token.ENDMARKER` tokens.
118+
119+
.. attribute:: exact_type
120+
121+
An integer identifying the specific operator type for
122+
:data:`~token.OP` tokens, as defined by the constants in :mod:`token`.
123+
For all other token types, this equals :attr:`type`.
124+
For example, a ``+`` token has :attr:`type` equal to :data:`~token.OP`
125+
and :attr:`exact_type` equal to :data:`~token.PLUS`.
126+
127+
.. versionadded:: 3.3
128+
129+
77130
All constants from the :mod:`token` module are also exported from
78131
:mod:`!tokenize`.
79132

0 commit comments

Comments
 (0)