Skip to content

Commit 7a9c81a

Browse files
committed
Merge remote-tracking branch 'upstream/main' into cpython-coverage.py
2 parents a1b2f61 + e6e3532 commit 7a9c81a

File tree

159 files changed

+3713
-1057
lines changed

Some content is hidden

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

159 files changed

+3713
-1057
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ Lib/test/test_interpreters/ @ericsnowcurrently
247247
/Tools/wasm/ @brettcannon
248248

249249
# SBOM
250+
/Misc/externals.spdx.json @sethmlarson
250251
/Misc/sbom.spdx.json @sethmlarson
251252
/Tools/build/generate_sbom.py @sethmlarson
252253

.github/workflows/jit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,13 @@ jobs:
7070
runner: ubuntu-latest
7171
compiler: gcc
7272
# These fail because of emulation, not because of the JIT:
73-
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv
73+
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv test_external_inspection
7474
- target: aarch64-unknown-linux-gnu/clang
7575
architecture: aarch64
7676
runner: ubuntu-latest
7777
compiler: clang
7878
# These fail because of emulation, not because of the JIT:
79-
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv
79+
exclude: test_unix_events test_init test_process_pool test_shutdown test_multiprocessing_fork test_cmd_line test_faulthandler test_os test_perf_profiler test_posix test_signal test_socket test_subprocess test_threading test_venv test_external_inspection
8080
env:
8181
CC: ${{ matrix.compiler }}
8282
steps:

Doc/library/abc.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,11 @@ a helper class :class:`ABC` to alternatively define ABCs through inheritance:
101101
subclass of the ABC. (This class method is called from the
102102
:meth:`~class.__subclasscheck__` method of the ABC.)
103103

104-
This method should return ``True``, ``False`` or ``NotImplemented``. If
104+
This method should return ``True``, ``False`` or :data:`NotImplemented`. If
105105
it returns ``True``, the *subclass* is considered a subclass of this ABC.
106106
If it returns ``False``, the *subclass* is not considered a subclass of
107107
this ABC, even if it would normally be one. If it returns
108-
``NotImplemented``, the subclass check is continued with the usual
108+
:data:`!NotImplemented`, the subclass check is continued with the usual
109109
mechanism.
110110

111111
.. XXX explain the "usual mechanism"

Doc/library/ast.rst

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2183,14 +2183,17 @@ and classes for traversing abstract syntax trees:
21832183
modified to correspond to :pep:`484` "signature type comments",
21842184
e.g. ``(str, int) -> List[str]``.
21852185

2186-
Also, setting ``feature_version`` to a tuple ``(major, minor)``
2187-
will attempt to parse using that Python version's grammar.
2188-
Currently ``major`` must equal to ``3``. For example, setting
2189-
``feature_version=(3, 4)`` will allow the use of ``async`` and
2190-
``await`` as variable names. The lowest supported version is
2191-
``(3, 7)``; the highest is ``sys.version_info[0:2]``.
2192-
2193-
If source contains a null character ('\0'), :exc:`ValueError` is raised.
2186+
Setting ``feature_version`` to a tuple ``(major, minor)`` will result in
2187+
a "best-effort" attempt to parse using that Python version's grammar.
2188+
For example, setting ``feature_version=(3, 9)`` will attempt to disallow
2189+
parsing of :keyword:`match` statements.
2190+
Currently ``major`` must equal to ``3``. The lowest supported version is
2191+
``(3, 7)`` (and this may increase in future Python versions);
2192+
the highest is ``sys.version_info[0:2]``. "Best-effort" attempt means there
2193+
is no guarantee that the parse (or success of the parse) is the same as
2194+
when run on the Python version corresponding to ``feature_version``.
2195+
2196+
If source contains a null character (``\0``), :exc:`ValueError` is raised.
21942197

21952198
.. warning::
21962199
Note that successfully parsing source code into an AST object doesn't

Doc/library/constants.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ A small number of constants live in the built-in namespace. They are:
3333
the other type; may be returned by the in-place binary special methods
3434
(e.g. :meth:`~object.__imul__`, :meth:`~object.__iand__`, etc.) for the same purpose.
3535
It should not be evaluated in a boolean context.
36-
``NotImplemented`` is the sole instance of the :data:`types.NotImplementedType` type.
36+
:data:`!NotImplemented` is the sole instance of the :data:`types.NotImplementedType` type.
3737

3838
.. note::
3939

40-
When a binary (or in-place) method returns ``NotImplemented`` the
40+
When a binary (or in-place) method returns :data:`!NotImplemented` the
4141
interpreter will try the reflected operation on the other type (or some
4242
other fallback, depending on the operator). If all attempts return
43-
``NotImplemented``, the interpreter will raise an appropriate exception.
44-
Incorrectly returning ``NotImplemented`` will result in a misleading
45-
error message or the ``NotImplemented`` value being returned to Python code.
43+
:data:`!NotImplemented`, the interpreter will raise an appropriate exception.
44+
Incorrectly returning :data:`!NotImplemented` will result in a misleading
45+
error message or the :data:`!NotImplemented` value being returned to Python code.
4646

4747
See :ref:`implementing-the-arithmetic-operations` for examples.
4848

4949
.. note::
5050

51-
``NotImplementedError`` and ``NotImplemented`` are not interchangeable,
51+
``NotImplementedError`` and :data:`!NotImplemented` are not interchangeable,
5252
even though they have similar names and purposes.
5353
See :exc:`NotImplementedError` for details on when to use it.
5454

5555
.. versionchanged:: 3.9
56-
Evaluating ``NotImplemented`` in a boolean context is deprecated. While
56+
Evaluating :data:`!NotImplemented` in a boolean context is deprecated. While
5757
it currently evaluates as true, it will emit a :exc:`DeprecationWarning`.
5858
It will raise a :exc:`TypeError` in a future version of Python.
5959

Doc/library/datetime.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1209,6 +1209,9 @@ Supported operations:
12091209

12101210
Naive and aware :class:`!datetime` objects are never equal.
12111211

1212+
If both comparands are aware, and have the same :attr:`!tzinfo` attribute,
1213+
the :attr:`!tzinfo` and :attr:`~.datetime.fold` attributes are ignored and
1214+
the base datetimes are compared.
12121215
If both comparands are aware and have different :attr:`~.datetime.tzinfo`
12131216
attributes, the comparison acts as comparands were first converted to UTC
12141217
datetimes except that the implementation never overflows.
@@ -1222,6 +1225,9 @@ Supported operations:
12221225
Order comparison between naive and aware :class:`.datetime` objects
12231226
raises :exc:`TypeError`.
12241227

1228+
If both comparands are aware, and have the same :attr:`!tzinfo` attribute,
1229+
the :attr:`!tzinfo` and :attr:`~.datetime.fold` attributes are ignored and
1230+
the base datetimes are compared.
12251231
If both comparands are aware and have different :attr:`~.datetime.tzinfo`
12261232
attributes, the comparison acts as comparands were first converted to UTC
12271233
datetimes except that the implementation never overflows.
@@ -1778,8 +1784,8 @@ Naive and aware :class:`!time` objects are never equal.
17781784
Order comparison between naive and aware :class:`!time` objects raises
17791785
:exc:`TypeError`.
17801786

1781-
If both comparands are aware, and have
1782-
the same :attr:`~.time.tzinfo` attribute, the common :attr:`!tzinfo` attribute is
1787+
If both comparands are aware, and have the same :attr:`~.time.tzinfo`
1788+
attribute, the :attr:`!tzinfo` and :attr:`!fold` attributes are
17831789
ignored and the base times are compared. If both comparands are aware and
17841790
have different :attr:`!tzinfo` attributes, the comparands are first adjusted by
17851791
subtracting their UTC offsets (obtained from ``self.utcoffset()``).

Doc/library/enum.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,9 @@ Data Types
400400

401401
results in the call ``int('1a', 16)`` and a value of ``17`` for the member.
402402

403+
..note:: When writing a custom ``__new__``, do not use ``super().__new__`` --
404+
call the appropriate ``__new__`` instead.
405+
403406
.. method:: Enum.__repr__(self)
404407

405408
Returns the string used for *repr()* calls. By default, returns the

Doc/library/exceptions.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -335,9 +335,9 @@ The following exceptions are the exceptions that are usually raised.
335335

336336
.. note::
337337

338-
``NotImplementedError`` and ``NotImplemented`` are not interchangeable,
338+
``NotImplementedError`` and :data:`NotImplemented` are not interchangeable,
339339
even though they have similar names and purposes. See
340-
:data:`NotImplemented` for details on when to use it.
340+
:data:`!NotImplemented` for details on when to use it.
341341

342342
.. exception:: OSError([arg])
343343
OSError(errno, strerror[, filename[, winerror[, filename2]]])

Doc/library/http.server.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,12 @@ the ``--cgi`` option::
520520
:mod:`http.server` command line ``--cgi`` support is being removed
521521
because :class:`CGIHTTPRequestHandler` is being removed.
522522

523+
.. warning::
524+
525+
:class:`CGIHTTPRequestHandler` and the ``--cgi`` command line option
526+
are not intended for use by untrusted clients and may be vulnerable
527+
to exploitation. Always use within a secure environment.
528+
523529
.. _http.server-security:
524530

525531
Security Considerations

Doc/library/importlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ ABC hierarchy::
265265
when invalidating the caches of all finders on :data:`sys.meta_path`.
266266

267267
.. versionchanged:: 3.4
268-
Returns ``None`` when called instead of ``NotImplemented``.
268+
Returns ``None`` when called instead of :data:`NotImplemented`.
269269

270270

271271
.. class:: PathEntryFinder

Doc/library/inspect.rst

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -665,9 +665,6 @@ function.
665665
Accepts a wide range of Python callables, from plain functions and classes to
666666
:func:`functools.partial` objects.
667667

668-
If the passed object has a ``__signature__`` attribute, this function
669-
returns it without further computations.
670-
671668
For objects defined in modules using stringized annotations
672669
(``from __future__ import annotations``), :func:`signature` will
673670
attempt to automatically un-stringize the annotations using
@@ -702,6 +699,13 @@ function.
702699
Python. For example, in CPython, some built-in functions defined in
703700
C provide no metadata about their arguments.
704701

702+
.. impl-detail::
703+
704+
If the passed object has a :attr:`!__signature__` attribute,
705+
we may use it to create the signature.
706+
The exact semantics are an implementation detail and are subject to
707+
unannounced changes. Consult the source code for current semantics.
708+
705709

706710
.. class:: Signature(parameters=None, *, return_annotation=Signature.empty)
707711

Doc/library/itertools.rst

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -778,7 +778,7 @@ The primary purpose of the itertools recipes is educational. The recipes show
778778
various ways of thinking about individual tools — for example, that
779779
``chain.from_iterable`` is related to the concept of flattening. The recipes
780780
also give ideas about ways that the tools can be combined — for example, how
781-
``compress()`` and ``range()`` can work together. The recipes also show patterns
781+
``starmap()`` and ``repeat()`` can work together. The recipes also show patterns
782782
for using itertools with the :mod:`operator` and :mod:`collections` modules as
783783
well as with the built-in itertools such as ``map()``, ``filter()``,
784784
``reversed()``, and ``enumerate()``.
@@ -863,10 +863,9 @@ which incur interpreter overhead.
863863
"Given a predicate that returns True or False, count the True results."
864864
return sum(map(pred, iterable))
865865

866-
def all_equal(iterable):
866+
def all_equal(iterable, key=None):
867867
"Returns True if all the elements are equal to each other."
868-
g = groupby(iterable)
869-
return next(g, True) and not next(g, False)
868+
return len(take(2, groupby(iterable, key))) <= 1
870869

871870
def first_true(iterable, default=False, pred=None):
872871
"""Returns the first true value in the iterable.
@@ -984,36 +983,17 @@ which incur interpreter overhead.
984983
""" Call a function repeatedly until an exception is raised.
985984

986985
Converts a call-until-exception interface to an iterator interface.
987-
Like builtins.iter(func, sentinel) but uses an exception instead
988-
of a sentinel to end the loop.
989-
990-
Priority queue iterator:
991-
iter_except(functools.partial(heappop, h), IndexError)
992-
993-
Non-blocking dictionary iterator:
994-
iter_except(d.popitem, KeyError)
995-
996-
Non-blocking deque iterator:
997-
iter_except(d.popleft, IndexError)
998-
999-
Non-blocking iterator over a producer Queue:
1000-
iter_except(q.get_nowait, Queue.Empty)
1001-
1002-
Non-blocking set iterator:
1003-
iter_except(s.pop, KeyError)
1004-
1005986
"""
987+
# iter_except(d.popitem, KeyError) --> non-blocking dictionary iterator
1006988
try:
1007989
if first is not None:
1008-
# For database APIs needing an initial call to db.first()
1009990
yield first()
1010991
while True:
1011992
yield func()
1012993
except exception:
1013994
pass
1014995

1015996

1016-
1017997
The following recipes have a more mathematical flavor:
1018998

1019999
.. testcode::
@@ -1225,6 +1205,8 @@ The following recipes have a more mathematical flavor:
12251205

12261206
>>> [all_equal(s) for s in ('', 'A', 'AAAA', 'AAAB', 'AAABA')]
12271207
[True, True, True, False, False]
1208+
>>> [all_equal(s, key=str.casefold) for s in ('', 'A', 'AaAa', 'AAAB', 'AAABA')]
1209+
[True, True, True, False, False]
12281210

12291211
>>> quantify(range(99), lambda x: x%2==0)
12301212
50

Doc/library/logging.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,27 @@ is the module's name in the Python package namespace.
7777

7878
.. class:: Logger
7979

80+
.. attribute:: Logger.name
81+
82+
This is the logger's name, and is the value that was passed to :func:`getLogger`
83+
to obtain the logger.
84+
85+
.. note:: This attribute should be treated as read-only.
86+
87+
.. attribute:: Logger.level
88+
89+
The threshold of this logger, as set by the :meth:`setLevel` method.
90+
91+
.. note:: Do not set this attribute directly - always use :meth:`setLevel`,
92+
which has checks for the level passed to it.
93+
94+
.. attribute:: Logger.parent
95+
96+
The parent logger of this logger. It may change based on later instantiation
97+
of loggers which are higher up in the namespace hierarchy.
98+
99+
.. note:: This value should be treated as read-only.
100+
80101
.. attribute:: Logger.propagate
81102

82103
If this attribute evaluates to true, events logged to this logger will be
@@ -108,6 +129,21 @@ is the module's name in the Python package namespace.
108129
scenario is to attach handlers only to the root logger, and to let
109130
propagation take care of the rest.
110131

132+
.. attribute:: Logger.handlers
133+
134+
The list of handlers directly attached to this logger instance.
135+
136+
.. note:: This attribute should be treated as read-only; it is normally changed via
137+
the :meth:`addHandler` and :meth:`removeHandler` methods, which use locks to ensure
138+
thread-safe operation.
139+
140+
.. attribute:: Logger.disabled
141+
142+
This attribute disables handling of any events. It is set to ``False`` in the
143+
initializer, and only changed by logging configuration code.
144+
145+
.. note:: This attribute should be treated as read-only.
146+
111147
.. method:: Logger.setLevel(level)
112148

113149
Sets the threshold for this logger to *level*. Logging messages which are less

Doc/library/numbers.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ Complex``. I'll consider ``a + b``:
166166
2. If ``A`` falls back to the boilerplate code, and it were to
167167
return a value from :meth:`~object.__add__`, we'd miss the possibility
168168
that ``B`` defines a more intelligent :meth:`~object.__radd__`, so the
169-
boilerplate should return :const:`NotImplemented` from
169+
boilerplate should return :data:`NotImplemented` from
170170
:meth:`!__add__`. (Or ``A`` may not implement :meth:`!__add__` at
171171
all.)
172172
3. Then ``B``'s :meth:`~object.__radd__` gets a chance. If it accepts

Doc/library/pickle.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ The :mod:`pickle` module exports three classes, :class:`Pickler`,
377377
Special reducer that can be defined in :class:`Pickler` subclasses. This
378378
method has priority over any reducer in the :attr:`dispatch_table`. It
379379
should conform to the same interface as a :meth:`~object.__reduce__` method, and
380-
can optionally return ``NotImplemented`` to fallback on
380+
can optionally return :data:`NotImplemented` to fallback on
381381
:attr:`dispatch_table`-registered reducers to pickle ``obj``.
382382

383383
For a detailed example, see :ref:`reducer_override`.
@@ -503,7 +503,7 @@ What can be pickled and unpickled?
503503
The following types can be pickled:
504504

505505
* built-in constants (``None``, ``True``, ``False``, ``Ellipsis``, and
506-
``NotImplemented``);
506+
:data:`NotImplemented`);
507507

508508
* integers, floating-point numbers, complex numbers;
509509

@@ -905,7 +905,7 @@ functions and classes.
905905
For those cases, it is possible to subclass from the :class:`Pickler` class and
906906
implement a :meth:`~Pickler.reducer_override` method. This method can return an
907907
arbitrary reduction tuple (see :meth:`~object.__reduce__`). It can alternatively return
908-
``NotImplemented`` to fallback to the traditional behavior.
908+
:data:`NotImplemented` to fallback to the traditional behavior.
909909

910910
If both the :attr:`~Pickler.dispatch_table` and
911911
:meth:`~Pickler.reducer_override` are defined, then

Doc/library/pyexpat.rst

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,37 @@ XMLParser Objects
196196
:exc:`ExpatError` to be raised with the :attr:`code` attribute set to
197197
``errors.codes[errors.XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING]``.
198198

199+
.. method:: xmlparser.SetReparseDeferralEnabled(enabled)
200+
201+
.. warning::
202+
203+
Calling ``SetReparseDeferralEnabled(False)`` has security implications,
204+
as detailed below; please make sure to understand these consequences
205+
prior to using the ``SetReparseDeferralEnabled`` method.
206+
207+
Expat 2.6.0 introduced a security mechanism called "reparse deferral"
208+
where instead of causing denial of service through quadratic runtime
209+
from reparsing large tokens, reparsing of unfinished tokens is now delayed
210+
by default until a sufficient amount of input is reached.
211+
Due to this delay, registered handlers may — depending of the sizing of
212+
input chunks pushed to Expat — no longer be called right after pushing new
213+
input to the parser. Where immediate feedback and taking over responsiblity
214+
of protecting against denial of service from large tokens are both wanted,
215+
calling ``SetReparseDeferralEnabled(False)`` disables reparse deferral
216+
for the current Expat parser instance, temporarily or altogether.
217+
Calling ``SetReparseDeferralEnabled(True)`` allows re-enabling reparse
218+
deferral.
219+
220+
.. versionadded:: 3.13
221+
222+
.. method:: xmlparser.GetReparseDeferralEnabled()
223+
224+
Returns whether reparse deferral is currently enabled for the given
225+
Expat parser instance.
226+
227+
.. versionadded:: 3.13
228+
229+
199230
:class:`xmlparser` objects have the following attributes:
200231

201232

0 commit comments

Comments
 (0)