Skip to content

Commit a59e2fc

Browse files
committed
Merge remote-tracking branch 'upstream/main' into pythongh-112984
2 parents 3a7425b + 2feec0f commit a59e2fc

File tree

93 files changed

+7469
-6286
lines changed

Some content is hidden

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

93 files changed

+7469
-6286
lines changed

Doc/conf.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@
245245
# be resolved, as the method is currently undocumented. For context, see
246246
# https://github.com/python/cpython/pull/103289.
247247
('py:meth', '_SubParsersAction.add_parser'),
248-
# Attributes that definitely should be documented better,
248+
# Attributes/methods/etc. that definitely should be documented better,
249249
# but are deferred for now:
250250
('py:attr', '__annotations__'),
251+
('py:meth', '__missing__'),
251252
('py:attr', '__wrapped__'),
253+
('py:meth', 'index'), # list.index, tuple.index, etc.
252254
]
253255

254256
# gh-106948: Copy standard C types declared in the "c:type" domain to the

Doc/library/ast.rst

+7
Original file line numberDiff line numberDiff line change
@@ -2457,6 +2457,13 @@ effects on the compilation of a program:
24572457
Generates and returns an abstract syntax tree instead of returning a
24582458
compiled code object.
24592459

2460+
.. data:: PyCF_OPTIMIZED_AST
2461+
2462+
The returned AST is optimized according to the *optimize* argument
2463+
in :func:`compile` or :func:`ast.parse`.
2464+
2465+
.. versionadded:: 3.13
2466+
24602467
.. data:: PyCF_TYPE_COMMENTS
24612468

24622469
Enables support for :pep:`484` and :pep:`526` style type comments

Doc/library/collections.abc.rst

+41-39
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
This module provides :term:`abstract base classes <abstract base class>` that
2424
can be used to test whether a class provides a particular interface; for
25-
example, whether it is :term:`hashable` or whether it is a mapping.
25+
example, whether it is :term:`hashable` or whether it is a :term:`mapping`.
2626

2727
An :func:`issubclass` or :func:`isinstance` test for an interface works in one
2828
of three ways.
@@ -73,7 +73,7 @@ of the API:
7373
>>> isinstance(D(), Sequence)
7474
True
7575

76-
In this example, class :class:`D` does not need to define
76+
In this example, class :class:`!D` does not need to define
7777
``__contains__``, ``__iter__``, and ``__reversed__`` because the
7878
:ref:`in-operator <comparisons>`, the :term:`iteration <iterable>`
7979
logic, and the :func:`reversed` function automatically fall back to
@@ -183,14 +183,14 @@ ABC Inherits from Abstract Methods Mi
183183

184184
.. rubric:: Footnotes
185185

186-
.. [1] These ABCs override :meth:`object.__subclasshook__` to support
186+
.. [1] These ABCs override :meth:`~abc.ABCMeta.__subclasshook__` to support
187187
testing an interface by verifying the required methods are present
188188
and have not been set to :const:`None`. This only works for simple
189189
interfaces. More complex interfaces require registration or direct
190190
subclassing.
191191
192192
.. [2] Checking ``isinstance(obj, Iterable)`` detects classes that are
193-
registered as :class:`Iterable` or that have an :meth:`__iter__`
193+
registered as :class:`Iterable` or that have an :meth:`~container.__iter__`
194194
method, but it does not detect classes that iterate with the
195195
:meth:`~object.__getitem__` method. The only reliable way to determine
196196
whether an object is :term:`iterable` is to call ``iter(obj)``.
@@ -202,26 +202,27 @@ Collections Abstract Base Classes -- Detailed Descriptions
202202

203203
.. class:: Container
204204

205-
ABC for classes that provide the :meth:`__contains__` method.
205+
ABC for classes that provide the :meth:`~object.__contains__` method.
206206

207207
.. class:: Hashable
208208

209-
ABC for classes that provide the :meth:`__hash__` method.
209+
ABC for classes that provide the :meth:`~object.__hash__` method.
210210

211211
.. class:: Sized
212212

213-
ABC for classes that provide the :meth:`__len__` method.
213+
ABC for classes that provide the :meth:`~object.__len__` method.
214214

215215
.. class:: Callable
216216

217-
ABC for classes that provide the :meth:`__call__` method.
217+
ABC for classes that provide the :meth:`~object.__call__` method.
218218

219219
.. class:: Iterable
220220

221-
ABC for classes that provide the :meth:`__iter__` method.
221+
ABC for classes that provide the :meth:`~container.__iter__` method.
222222

223223
Checking ``isinstance(obj, Iterable)`` detects classes that are registered
224-
as :class:`Iterable` or that have an :meth:`__iter__` method, but it does
224+
as :class:`Iterable` or that have an :meth:`~container.__iter__` method,
225+
but it does
225226
not detect classes that iterate with the :meth:`~object.__getitem__` method.
226227
The only reliable way to determine whether an object is :term:`iterable`
227228
is to call ``iter(obj)``.
@@ -240,17 +241,17 @@ Collections Abstract Base Classes -- Detailed Descriptions
240241

241242
.. class:: Reversible
242243

243-
ABC for iterable classes that also provide the :meth:`__reversed__`
244+
ABC for iterable classes that also provide the :meth:`~object.__reversed__`
244245
method.
245246

246247
.. versionadded:: 3.6
247248

248249
.. class:: Generator
249250

250-
ABC for generator classes that implement the protocol defined in
251-
:pep:`342` that extends iterators with the :meth:`~generator.send`,
251+
ABC for :term:`generator` classes that implement the protocol defined in
252+
:pep:`342` that extends :term:`iterators <iterator>` with the
253+
:meth:`~generator.send`,
252254
:meth:`~generator.throw` and :meth:`~generator.close` methods.
253-
See also the definition of :term:`generator`.
254255

255256
.. versionadded:: 3.5
256257

@@ -261,7 +262,7 @@ Collections Abstract Base Classes -- Detailed Descriptions
261262
ABCs for read-only and mutable :term:`sequences <sequence>`.
262263

263264
Implementation note: Some of the mixin methods, such as
264-
:meth:`__iter__`, :meth:`__reversed__` and :meth:`index`, make
265+
:meth:`~container.__iter__`, :meth:`~object.__reversed__` and :meth:`index`, make
265266
repeated calls to the underlying :meth:`~object.__getitem__` method.
266267
Consequently, if :meth:`~object.__getitem__` is implemented with constant
267268
access speed, the mixin methods will have linear performance;
@@ -282,7 +283,7 @@ Collections Abstract Base Classes -- Detailed Descriptions
282283
.. class:: Set
283284
MutableSet
284285

285-
ABCs for read-only and mutable sets.
286+
ABCs for read-only and mutable :ref:`sets <types-set>`.
286287

287288
.. class:: Mapping
288289
MutableMapping
@@ -299,42 +300,42 @@ Collections Abstract Base Classes -- Detailed Descriptions
299300
.. class:: Awaitable
300301

301302
ABC for :term:`awaitable` objects, which can be used in :keyword:`await`
302-
expressions. Custom implementations must provide the :meth:`__await__`
303-
method.
303+
expressions. Custom implementations must provide the
304+
:meth:`~object.__await__` method.
304305

305306
:term:`Coroutine <coroutine>` objects and instances of the
306307
:class:`~collections.abc.Coroutine` ABC are all instances of this ABC.
307308

308309
.. note::
309-
In CPython, generator-based coroutines (generators decorated with
310-
:func:`types.coroutine`) are
311-
*awaitables*, even though they do not have an :meth:`__await__` method.
310+
In CPython, generator-based coroutines (:term:`generators <generator>`
311+
decorated with :func:`@types.coroutine <types.coroutine>`) are
312+
*awaitables*, even though they do not have an :meth:`~object.__await__` method.
312313
Using ``isinstance(gencoro, Awaitable)`` for them will return ``False``.
313314
Use :func:`inspect.isawaitable` to detect them.
314315

315316
.. versionadded:: 3.5
316317

317318
.. class:: Coroutine
318319

319-
ABC for coroutine compatible classes. These implement the
320+
ABC for :term:`coroutine` compatible classes. These implement the
320321
following methods, defined in :ref:`coroutine-objects`:
321322
:meth:`~coroutine.send`, :meth:`~coroutine.throw`, and
322323
:meth:`~coroutine.close`. Custom implementations must also implement
323-
:meth:`__await__`. All :class:`Coroutine` instances are also instances of
324-
:class:`Awaitable`. See also the definition of :term:`coroutine`.
324+
:meth:`~object.__await__`. All :class:`Coroutine` instances are also
325+
instances of :class:`Awaitable`.
325326

326327
.. note::
327-
In CPython, generator-based coroutines (generators decorated with
328-
:func:`types.coroutine`) are
329-
*awaitables*, even though they do not have an :meth:`__await__` method.
328+
In CPython, generator-based coroutines (:term:`generators <generator>`
329+
decorated with :func:`@types.coroutine <types.coroutine>`) are
330+
*awaitables*, even though they do not have an :meth:`~object.__await__` method.
330331
Using ``isinstance(gencoro, Coroutine)`` for them will return ``False``.
331332
Use :func:`inspect.isawaitable` to detect them.
332333

333334
.. versionadded:: 3.5
334335

335336
.. class:: AsyncIterable
336337

337-
ABC for classes that provide ``__aiter__`` method. See also the
338+
ABC for classes that provide an ``__aiter__`` method. See also the
338339
definition of :term:`asynchronous iterable`.
339340

340341
.. versionadded:: 3.5
@@ -348,7 +349,7 @@ Collections Abstract Base Classes -- Detailed Descriptions
348349

349350
.. class:: AsyncGenerator
350351

351-
ABC for asynchronous generator classes that implement the protocol
352+
ABC for :term:`asynchronous generator` classes that implement the protocol
352353
defined in :pep:`525` and :pep:`492`.
353354

354355
.. versionadded:: 3.6
@@ -373,9 +374,9 @@ particular functionality, for example::
373374
Several of the ABCs are also useful as mixins that make it easier to develop
374375
classes supporting container APIs. For example, to write a class supporting
375376
the full :class:`Set` API, it is only necessary to supply the three underlying
376-
abstract methods: :meth:`__contains__`, :meth:`__iter__`, and :meth:`__len__`.
377-
The ABC supplies the remaining methods such as :meth:`__and__` and
378-
:meth:`isdisjoint`::
377+
abstract methods: :meth:`~object.__contains__`, :meth:`~container.__iter__`, and
378+
:meth:`~object.__len__`. The ABC supplies the remaining methods such as
379+
:meth:`!__and__` and :meth:`~frozenset.isdisjoint`::
379380

380381
class ListBasedSet(collections.abc.Set):
381382
''' Alternate set implementation favoring space over speed
@@ -403,23 +404,24 @@ Notes on using :class:`Set` and :class:`MutableSet` as a mixin:
403404

404405
(1)
405406
Since some set operations create new sets, the default mixin methods need
406-
a way to create new instances from an iterable. The class constructor is
407+
a way to create new instances from an :term:`iterable`. The class constructor is
407408
assumed to have a signature in the form ``ClassName(iterable)``.
408-
That assumption is factored-out to an internal classmethod called
409-
:meth:`_from_iterable` which calls ``cls(iterable)`` to produce a new set.
409+
That assumption is factored-out to an internal :class:`classmethod` called
410+
:meth:`!_from_iterable` which calls ``cls(iterable)`` to produce a new set.
410411
If the :class:`Set` mixin is being used in a class with a different
411-
constructor signature, you will need to override :meth:`_from_iterable`
412+
constructor signature, you will need to override :meth:`!_from_iterable`
412413
with a classmethod or regular method that can construct new instances from
413414
an iterable argument.
414415

415416
(2)
416417
To override the comparisons (presumably for speed, as the
417-
semantics are fixed), redefine :meth:`__le__` and :meth:`__ge__`,
418+
semantics are fixed), redefine :meth:`~object.__le__` and
419+
:meth:`~object.__ge__`,
418420
then the other operations will automatically follow suit.
419421

420422
(3)
421-
The :class:`Set` mixin provides a :meth:`_hash` method to compute a hash value
422-
for the set; however, :meth:`__hash__` is not defined because not all sets
423+
The :class:`Set` mixin provides a :meth:`!_hash` method to compute a hash value
424+
for the set; however, :meth:`~object.__hash__` is not defined because not all sets
423425
are :term:`hashable` or immutable. To add set hashability using mixins,
424426
inherit from both :meth:`Set` and :meth:`Hashable`, then define
425427
``__hash__ = Set._hash``.

Doc/library/csv.rst

+7-4
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,11 @@ The :mod:`csv` module defines the following functions:
5555

5656
.. function:: reader(csvfile, dialect='excel', **fmtparams)
5757

58-
Return a reader object which will iterate over lines in the given *csvfile*.
59-
*csvfile* can be any object which supports the :term:`iterator` protocol and returns a
60-
string each time its :meth:`!__next__` method is called --- :term:`file objects
61-
<file object>` and list objects are both suitable. If *csvfile* is a file object,
58+
Return a :ref:`reader object <reader-objects>` that will process
59+
lines from the given *csvfile*. A csvfile must be an iterable of
60+
strings, each in the reader's defined csv format.
61+
A csvfile is most commonly a file-like object or list.
62+
If *csvfile* is a file object,
6263
it should be opened with ``newline=''``. [1]_ An optional
6364
*dialect* parameter can be given which is used to define a set of parameters
6465
specific to a particular CSV dialect. It may be an instance of a subclass of
@@ -449,6 +450,8 @@ Dialects support the following attributes:
449450
When ``True``, raise exception :exc:`Error` on bad CSV input.
450451
The default is ``False``.
451452

453+
.. _reader-objects:
454+
452455
Reader Objects
453456
--------------
454457

Doc/library/datetime.rst

+2-1
Original file line numberDiff line numberDiff line change
@@ -1985,7 +1985,8 @@ Examples of working with a :class:`.time` object::
19851985
American EST and EDT.
19861986

19871987
Special requirement for pickling: A :class:`tzinfo` subclass must have an
1988-
:meth:`__init__` method that can be called with no arguments, otherwise it can be
1988+
:meth:`~object.__init__` method that can be called with no arguments,
1989+
otherwise it can be
19891990
pickled but possibly not unpickled again. This is a technical requirement that
19901991
may be relaxed in the future.
19911992

Doc/library/email.utils.rst

+15-4
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,18 @@ of the new API.
5858
begins with angle brackets, they are stripped off.
5959

6060

61-
.. function:: parseaddr(address)
61+
.. function:: parseaddr(address, *, strict=True)
6262

6363
Parse address -- which should be the value of some address-containing field such
6464
as :mailheader:`To` or :mailheader:`Cc` -- into its constituent *realname* and
6565
*email address* parts. Returns a tuple of that information, unless the parse
6666
fails, in which case a 2-tuple of ``('', '')`` is returned.
6767

68+
If *strict* is true, use a strict parser which rejects malformed inputs.
69+
70+
.. versionchanged:: 3.13
71+
Add *strict* optional parameter and reject malformed inputs by default.
72+
6873

6974
.. function:: formataddr(pair, charset='utf-8')
7075

@@ -82,12 +87,15 @@ of the new API.
8287
Added the *charset* option.
8388

8489

85-
.. function:: getaddresses(fieldvalues)
90+
.. function:: getaddresses(fieldvalues, *, strict=True)
8691

8792
This method returns a list of 2-tuples of the form returned by ``parseaddr()``.
8893
*fieldvalues* is a sequence of header field values as might be returned by
89-
:meth:`Message.get_all <email.message.Message.get_all>`. Here's a simple
90-
example that gets all the recipients of a message::
94+
:meth:`Message.get_all <email.message.Message.get_all>`.
95+
96+
If *strict* is true, use a strict parser which rejects malformed inputs.
97+
98+
Here's a simple example that gets all the recipients of a message::
9199

92100
from email.utils import getaddresses
93101

@@ -97,6 +105,9 @@ of the new API.
97105
resent_ccs = msg.get_all('resent-cc', [])
98106
all_recipients = getaddresses(tos + ccs + resent_tos + resent_ccs)
99107

108+
.. versionchanged:: 3.13
109+
Add *strict* optional parameter and reject malformed inputs by default.
110+
100111

101112
.. function:: parsedate(date)
102113

Doc/library/exceptions.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -1009,9 +1009,9 @@ their subgroups based on the types of the contained exceptions.
10091009
True
10101010

10111011

1012-
Note that :exc:`BaseExceptionGroup` defines :meth:`__new__`, so
1012+
Note that :exc:`BaseExceptionGroup` defines :meth:`~object.__new__`, so
10131013
subclasses that need a different constructor signature need to
1014-
override that rather than :meth:`__init__`. For example, the following
1014+
override that rather than :meth:`~object.__init__`. For example, the following
10151015
defines an exception group subclass which accepts an exit_code and
10161016
and constructs the group's message from it. ::
10171017

Doc/library/fractions.rst

+30-7
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ another rational number, or from a string.
106106
presentation types ``"e"``, ``"E"``, ``"f"``, ``"F"``, ``"g"``, ``"G"``
107107
and ``"%""``.
108108

109+
.. versionchanged:: 3.13
110+
Formatting of :class:`Fraction` instances without a presentation type
111+
now supports fill, alignment, sign handling, minimum width and grouping.
112+
109113
.. attribute:: numerator
110114

111115
Numerator of the Fraction in lowest term.
@@ -201,17 +205,36 @@ another rational number, or from a string.
201205

202206
.. method:: __format__(format_spec, /)
203207

204-
Provides support for float-style formatting of :class:`Fraction`
205-
instances via the :meth:`str.format` method, the :func:`format` built-in
206-
function, or :ref:`Formatted string literals <f-strings>`. The
207-
presentation types ``"e"``, ``"E"``, ``"f"``, ``"F"``, ``"g"``, ``"G"``
208-
and ``"%"`` are supported. For these presentation types, formatting for a
209-
:class:`Fraction` object ``x`` follows the rules outlined for
210-
the :class:`float` type in the :ref:`formatspec` section.
208+
Provides support for formatting of :class:`Fraction` instances via the
209+
:meth:`str.format` method, the :func:`format` built-in function, or
210+
:ref:`Formatted string literals <f-strings>`.
211+
212+
If the ``format_spec`` format specification string does not end with one
213+
of the presentation types ``'e'``, ``'E'``, ``'f'``, ``'F'``, ``'g'``,
214+
``'G'`` or ``'%'`` then formatting follows the general rules for fill,
215+
alignment, sign handling, minimum width, and grouping as described in the
216+
:ref:`format specification mini-language <formatspec>`. The "alternate
217+
form" flag ``'#'`` is supported: if present, it forces the output string
218+
to always include an explicit denominator, even when the value being
219+
formatted is an exact integer. The zero-fill flag ``'0'`` is not
220+
supported.
221+
222+
If the ``format_spec`` format specification string ends with one of
223+
the presentation types ``'e'``, ``'E'``, ``'f'``, ``'F'``, ``'g'``,
224+
``'G'`` or ``'%'`` then formatting follows the rules outlined for the
225+
:class:`float` type in the :ref:`formatspec` section.
211226

212227
Here are some examples::
213228

214229
>>> from fractions import Fraction
230+
>>> format(Fraction(103993, 33102), '_')
231+
'103_993/33_102'
232+
>>> format(Fraction(1, 7), '.^+10')
233+
'...+1/7...'
234+
>>> format(Fraction(3, 1), '')
235+
'3'
236+
>>> format(Fraction(3, 1), '#')
237+
'3/1'
215238
>>> format(Fraction(1, 7), '.40g')
216239
'0.1428571428571428571428571428571428571429'
217240
>>> format(Fraction('1234567.855'), '_.2f')

0 commit comments

Comments
 (0)