Skip to content

Commit 36c6389

Browse files
authored
Merge branch 'main' into promote/mdiff
2 parents b8977c8 + c700121 commit 36c6389

123 files changed

Lines changed: 3849 additions & 736 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/library/ast.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,7 @@ and classes for traversing abstract syntax trees:
22542254

22552255
In addition, if ``mode`` is ``'func_type'``, the input syntax is
22562256
modified to correspond to :pep:`484` "signature type comments",
2257-
e.g. ``(str, int) -> List[str]``.
2257+
for example ``(str, int) -> List[str]``.
22582258

22592259
Setting ``feature_version`` to a tuple ``(major, minor)`` will result in
22602260
a "best-effort" attempt to parse using that Python version's grammar.

Doc/library/asyncio-task.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ and reliable way to wait for all tasks in the group to finish.
356356
The signature matches that of :func:`asyncio.create_task`.
357357
If the task group is inactive (e.g. not yet entered,
358358
already finished, or in the process of shutting down),
359-
we will close the given ``coro``.
359+
we will close the given ``coro`` and raise :exc:`RuntimeError`.
360360

361361
.. versionchanged:: 3.13
362362

Doc/library/concurrent.interpreters.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ objects are either directly shared or copied efficiently. For example:
191191
* :class:`float`
192192
* :class:`tuple` (of similarly supported objects)
193193

194-
There is a small number of Python types that actually share mutable
194+
There are a small number of Python types that actually share mutable
195195
data between interpreters:
196196

197197
* :class:`memoryview`
@@ -274,7 +274,7 @@ Interpreter objects
274274

275275
.. method:: call(callable, /, *args, **kwargs)
276276

277-
Return the result of calling running the given function in the
277+
Return the result of running the given function in the
278278
interpreter (in the current thread).
279279

280280
.. _interp-call-in-thread:

Doc/library/ctypes.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -715,8 +715,11 @@ Specifying function pointers using type annotations
715715
and do not have to match the underlying C implementation.
716716

717717
If the decorated function does not have a return type annotation, a
718-
:exc:`ValueError` is raised. If the name of the function does not exist
719-
in *dll*, an :exc:`AttributeError` is raised.
718+
:exc:`ValueError` is raised. A :exc:`ValueError` is also raised if it has a
719+
keyword-only, ``*args``, or ``**kwargs`` parameter, since
720+
:attr:`~ctypes._CFuncPtr.argtypes` describes positional arguments only. If
721+
the name of the function does not exist in *dll*, an :exc:`AttributeError`
722+
is raised.
720723

721724
For example::
722725

Doc/library/functions.rst

Lines changed: 73 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,54 @@ are always available. They are listed here in alphabetical order.
6565

6666

6767
.. function:: aiter(async_iterable, /)
68+
aiter(callable, /, stop_value, *, stop_exception=StopAsyncIteration)
69+
aiter(callable, /, *, stop_exception)
70+
71+
Return an :term:`asynchronous iterator` object.
72+
The first argument is interpreted very differently
73+
depending on the presence of the other arguments.
74+
Without other arguments,
75+
the single argument must be an :term:`asynchronous iterable`,
76+
and the result is equivalent to calling ``x.__aiter__()``.
77+
78+
If *stop_value* or *stop_exception* is given,
79+
then the first argument must be a callable object.
80+
The asynchronous iterator created in this case
81+
calls *callable* with no arguments and awaits the result
82+
for each call to its :meth:`~object.__anext__` method;
83+
if the awaited value is equal to *stop_value*,
84+
or if the call raises an exception matching *stop_exception*,
85+
:exc:`StopAsyncIteration` will be raised,
86+
otherwise the value will be returned.
87+
The callable is only called when the result of :meth:`~object.__anext__`
88+
is awaited.
89+
90+
*stop_exception* is an exception class or a tuple of exception classes.
91+
If *stop_value* is not specified,
92+
the iteration stops only when the callable raises an exception.
93+
If the callable raises :exc:`StopAsyncIteration`
94+
which does not match *stop_exception*,
95+
it is replaced with a :exc:`RuntimeError`,
96+
as for asynchronous generators (see :pep:`525`).
97+
98+
For example, reading fixed-size chunks from an asynchronous stream
99+
until the end of file is reached::
68100

69-
Return an :term:`asynchronous iterator` for an :term:`asynchronous iterable`.
70-
Equivalent to calling ``x.__aiter__()``.
101+
from functools import partial
102+
async for chunk in aiter(partial(reader.read, 1024), b''):
103+
process_chunk(chunk)
104+
105+
Or consuming an :class:`asyncio.Queue` until it is shut down::
71106

72-
Note: Unlike :func:`iter`, :func:`aiter` has no 2-argument variant.
107+
from asyncio import QueueShutDown
108+
async for item in aiter(queue.get, stop_exception=QueueShutDown):
109+
process_item(item)
73110

74111
.. versionadded:: 3.10
75112

113+
.. versionchanged:: next
114+
Added the *stop_value* and *stop_exception* parameters.
115+
76116
.. function:: all(iterable, /)
77117

78118
Return ``True`` if all elements of the *iterable* are true (or if the iterable
@@ -1143,22 +1183,34 @@ are always available. They are listed here in alphabetical order.
11431183

11441184

11451185
.. function:: iter(iterable, /)
1146-
iter(callable, sentinel, /)
1186+
iter(callable, /, stop_value, *, stop_exception=StopIteration)
1187+
iter(callable, /, *, stop_exception)
11471188
11481189
Return an :term:`iterator` object. The first argument is interpreted very
1149-
differently depending on the presence of the second argument. Without a
1150-
second argument, the single argument must be a collection object which supports the
1190+
differently depending on the presence of the other arguments. Without other
1191+
arguments, the single argument must be a collection object which supports the
11511192
:term:`iterable` protocol (the :meth:`~object.__iter__` method),
11521193
or it must support
11531194
the sequence protocol (the :meth:`~object.__getitem__` method with integer arguments
11541195
starting at ``0``). If it does not support either of those protocols,
1155-
:exc:`TypeError` is raised. If the second argument, *sentinel*, is given,
1196+
:exc:`TypeError` is raised.
1197+
1198+
If *stop_value* or *stop_exception* is given,
11561199
then the first argument must be a callable object. The iterator created in this case
11571200
will call *callable* with no arguments for each call to its
11581201
:meth:`~iterator.__next__` method; if the value returned is equal to
1159-
*sentinel*, :exc:`StopIteration` will be raised, otherwise the value will
1202+
*stop_value*, or if the call raises an exception matching *stop_exception*,
1203+
:exc:`StopIteration` will be raised, otherwise the value will
11601204
be returned.
11611205

1206+
*stop_exception* is an exception class or a tuple of exception classes.
1207+
If *stop_value* is not specified,
1208+
the iteration stops only when the callable raises an exception.
1209+
If the callable raises :exc:`StopIteration`
1210+
which does not match *stop_exception*,
1211+
it is replaced with a :exc:`RuntimeError`,
1212+
as for generators (see :pep:`479`).
1213+
11621214
See also :ref:`typeiter`.
11631215

11641216
One useful application of the second form of :func:`iter` is to build a
@@ -1170,6 +1222,19 @@ are always available. They are listed here in alphabetical order.
11701222
for block in iter(partial(f.read, 64), b''):
11711223
process_block(block)
11721224

1225+
*stop_exception* is useful for callables
1226+
which report exhaustion by raising an exception
1227+
instead of returning a special value.
1228+
For example, draining a queue::
1229+
1230+
import queue
1231+
for item in iter(input_queue.get_nowait, stop_exception=queue.Empty):
1232+
process_item(item)
1233+
1234+
.. versionchanged:: next
1235+
Added the *stop_exception* parameter
1236+
and allowed passing *stop_value* by keyword.
1237+
11731238

11741239
.. function:: len(object, /)
11751240

Doc/library/mimetypes.rst

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,8 @@ than one MIME-type database; it provides an interface similar to the one of the
211211
.. class:: MimeTypes(filenames=(), strict=True)
212212

213213
This class represents a MIME-types database. By default, it provides access to
214-
the same database as the rest of this module. The initial database is a copy of
215-
that provided by the module, and may be extended by loading additional
214+
the same database as the rest of this module. The initial database is created from
215+
Python's built-in MIME type tables. It may be extended by loading additional
216216
:file:`mime.types`\ -style files into the database using the :meth:`read` or
217217
:meth:`readfp` methods. The mapping dictionaries may also be cleared before
218218
loading additional data if the default data is not desired.
@@ -226,30 +226,32 @@ than one MIME-type database; it provides an interface similar to the one of the
226226
Dictionary mapping suffixes to suffixes. This is used to allow recognition of
227227
encoded files for which the encoding and the type are indicated by the same
228228
extension. For example, the :file:`.tgz` extension is mapped to :file:`.tar.gz`
229-
to allow the encoding and type to be recognized separately. This is initially a
230-
copy of the global :data:`suffix_map` defined in the module.
229+
to allow the encoding and type to be recognized separately.
230+
This is initialized with some predefined values.
231231

232232

233233
.. attribute:: MimeTypes.encodings_map
234234

235-
Dictionary mapping filename extensions to encoding types. This is initially a
236-
copy of the global :data:`encodings_map` defined in the module.
235+
Dictionary mapping filename extensions to encoding types.
236+
This is initialized with some predefined values.
237237

238238

239239
.. attribute:: MimeTypes.types_map
240240

241241
Tuple containing two dictionaries, mapping filename extensions to MIME types:
242242
the first dictionary is for the non-standards types and the second one is for
243-
the standard types. They are initialized by :data:`common_types` and
244-
:data:`types_map`.
243+
the standard types.
244+
They are initialized with some predefined values and MIME type
245+
information loaded from files specified by the *filenames* argument.
245246

246247

247248
.. attribute:: MimeTypes.types_map_inv
248249

249250
Tuple containing two dictionaries, mapping MIME types to a list of filename
250251
extensions: the first dictionary is for the non-standards types and the
251-
second one is for the standard types. They are initialized by
252-
:data:`common_types` and :data:`types_map`.
252+
second one is for the standard types.
253+
They are initialized with some predefined values and MIME type
254+
information loaded from files specified by the *filenames* argument.
253255

254256

255257
.. method:: MimeTypes.guess_extension(type, strict=True)

Doc/library/pyexpat.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,20 @@ XMLParser Objects
172172
or ``None`` if :meth:`SetBase` hasn't been called.
173173

174174

175+
.. method:: xmlparser.GetSpecifiedAttributeCount()
176+
177+
Return the index just past the attributes given in the start tag.
178+
Attributes defaulted from the DTD follow the specified ones,
179+
so attributes at lower indices in the list
180+
passed to :attr:`StartElementHandler` were given in the start tag.
181+
Each attribute takes two items in that list,
182+
its name and its value.
183+
Only meaningful inside a :attr:`StartElementHandler` call,
184+
and only if :attr:`ordered_attributes` is true.
185+
186+
.. versionadded:: next
187+
188+
175189
.. method:: xmlparser.GetInputContext()
176190

177191
Returns the input data that generated the current event as a string. The data is

Doc/library/site.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,10 @@ Module contents
453453

454454
Return a list containing all global site-packages directories.
455455

456-
For each directory present in *prefixes* (or :data:`PREFIXES` if *prefixes*
457-
is ``None``), this function will find its site-packages subdirectory
458-
depending on the system environment, and will return a list of full paths.
456+
For each directory given in *prefixes* (or :data:`PREFIXES` if *prefixes*
457+
is ``None``), this function will compute its site-packages subdirectory
458+
depending on the system environment, and will return a list of full paths,
459+
which are not checked for existence.
459460

460461
.. versionadded:: 3.2
461462

Doc/library/xml.dom.minidom.rst

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -245,21 +245,47 @@ rules apply:
245245
Instead, :mod:`!xml.dom.minidom` uses standard Python exceptions such as
246246
:exc:`TypeError` and :exc:`AttributeError`.
247247

248-
* :class:`NodeList` objects are implemented using Python's built-in list type.
249-
These objects provide the interface defined in the DOM specification, but with
250-
earlier versions of Python they do not support the official API. They are,
251-
however, much more "Pythonic" than the interface defined in the W3C
252-
recommendations.
248+
* Each of the :class:`~xml.dom.NodeList` and :class:`~xml.dom.NamedNodeMap`
249+
interfaces has two implementations, which provide additional methods and
250+
operations.
251+
252+
:attr:`~xml.dom.Node.childNodes` is a subclass of :class:`list`, or, for
253+
nodes which cannot have children, a subclass of :class:`tuple`.
254+
It supports iteration, concatenation, indexing and slicing.
255+
256+
:attr:`~xml.dom.Node.attributes` supports ``len()``, the :keyword:`in`
257+
operator, subscription by a name or by a ``(namespaceURI, localName)``
258+
tuple, assignment and deletion, and the methods :meth:`!get`, :meth:`!keys`,
259+
:meth:`!keysNS`, :meth:`!values`, :meth:`!items` and :meth:`!itemsNS`.
260+
:attr:`~xml.dom.DocumentType.entities` and
261+
:attr:`~xml.dom.DocumentType.notations` are read-only and support only
262+
``len()`` and subscription by a name.
263+
264+
* :attr:`~xml.dom.Document.strictErrorChecking` is always ``False``.
265+
266+
.. versionchanged:: next
267+
Previously, :attr:`~xml.dom.Attr.specified` was always ``False``.
268+
269+
* The constraints of the DOM are now enforced,
270+
and the corresponding exceptions are raised.
271+
272+
.. versionchanged:: next
273+
Previously, many invalid operations silently succeeded
274+
and produced an invalid document,
275+
but removing an absent attribute raised :exc:`~xml.dom.NotFoundErr`.
253276

254277
The following interfaces have no implementation in :mod:`!xml.dom.minidom`:
255278

256279
* :class:`DOMTimeStamp`
257280

258-
* :class:`EntityReference`
259-
260-
Most of these reflect information in the XML document that is not of general
281+
This reflects information in the XML document that is not of general
261282
utility to most DOM users.
262283

284+
.. versionchanged:: next
285+
:class:`~xml.dom.EntityReference` is now implemented.
286+
Note that the parser expands entity references,
287+
so they only occur in a document if created explicitly.
288+
263289
.. rubric:: Footnotes
264290

265291
.. [1] The encoding name included in the XML output should conform to

0 commit comments

Comments
 (0)