Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b03e474

Browse files
committed
Merge branch 'main' into gh-114847
2 parents 197c871 + fc8007e commit b03e474

32 files changed

Lines changed: 728 additions & 286 deletions

.github/workflows/project-updater.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ jobs:
2323
- { project: 32, label: sprint }
2424

2525
steps:
26-
- uses: actions/add-to-project@v0.6.0
26+
- uses: actions/add-to-project@v1.0.0
2727
with:
2828
project-url: https://github.com/orgs/python/projects/${{ matrix.project }}
2929
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}

Doc/library/asyncio-task.rst

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -867,19 +867,50 @@ Waiting Primitives
867867

868868
.. function:: as_completed(aws, *, timeout=None)
869869

870-
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws*
871-
iterable concurrently. Return an iterator of coroutines.
872-
Each coroutine returned can be awaited to get the earliest next
873-
result from the iterable of the remaining awaitables.
874-
875-
Raises :exc:`TimeoutError` if the timeout occurs before
876-
all Futures are done.
877-
878-
Example::
879-
880-
for coro in as_completed(aws):
881-
earliest_result = await coro
882-
# ...
870+
Run :ref:`awaitable objects <asyncio-awaitables>` in the *aws* iterable
871+
concurrently. The returned object can be iterated to obtain the results
872+
of the awaitables as they finish.
873+
874+
The object returned by ``as_completed()`` can be iterated as an
875+
:term:`asynchronous iterator` or a plain :term:`iterator`. When asynchronous
876+
iteration is used, the originally-supplied awaitables are yielded if they
877+
are tasks or futures. This makes it easy to correlate previously-scheduled
878+
tasks with their results. Example::
879+
880+
ipv4_connect = create_task(open_connection("127.0.0.1", 80))
881+
ipv6_connect = create_task(open_connection("::1", 80))
882+
tasks = [ipv4_connect, ipv6_connect]
883+
884+
async for earliest_connect in as_completed(tasks):
885+
# earliest_connect is done. The result can be obtained by
886+
# awaiting it or calling earliest_connect.result()
887+
reader, writer = await earliest_connect
888+
889+
if earliest_connect is ipv6_connect:
890+
print("IPv6 connection established.")
891+
else:
892+
print("IPv4 connection established.")
893+
894+
During asynchronous iteration, implicitly-created tasks will be yielded for
895+
supplied awaitables that aren't tasks or futures.
896+
897+
When used as a plain iterator, each iteration yields a new coroutine that
898+
returns the result or raises the exception of the next completed awaitable.
899+
This pattern is compatible with Python versions older than 3.13::
900+
901+
ipv4_connect = create_task(open_connection("127.0.0.1", 80))
902+
ipv6_connect = create_task(open_connection("::1", 80))
903+
tasks = [ipv4_connect, ipv6_connect]
904+
905+
for next_connect in as_completed(tasks):
906+
# next_connect is not one of the original task objects. It must be
907+
# awaited to obtain the result value or raise the exception of the
908+
# awaitable that finishes next.
909+
reader, writer = await next_connect
910+
911+
A :exc:`TimeoutError` is raised if the timeout occurs before all awaitables
912+
are done. This is raised by the ``async for`` loop during asynchronous
913+
iteration or by the coroutines yielded during plain iteration.
883914

884915
.. versionchanged:: 3.10
885916
Removed the *loop* parameter.
@@ -891,6 +922,10 @@ Waiting Primitives
891922
.. versionchanged:: 3.12
892923
Added support for generators yielding tasks.
893924

925+
.. versionchanged:: 3.13
926+
The result can now be used as either an :term:`asynchronous iterator`
927+
or as a plain :term:`iterator` (previously it was only a plain iterator).
928+
894929

895930
Running in Threads
896931
==================

Doc/library/stdtypes.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2339,7 +2339,13 @@ String objects have one unique built-in operation: the ``%`` operator (modulo).
23392339
This is also known as the string *formatting* or *interpolation* operator.
23402340
Given ``format % values`` (where *format* is a string), ``%`` conversion
23412341
specifications in *format* are replaced with zero or more elements of *values*.
2342-
The effect is similar to using the :c:func:`sprintf` in the C language.
2342+
The effect is similar to using the :c:func:`sprintf` function in the C language.
2343+
For example:
2344+
2345+
.. doctest::
2346+
2347+
>>> print('%s has %d quote types.' % ('Python', 2))
2348+
Python has 2 quote types.
23432349

23442350
If *format* requires a single argument, *values* may be a single non-tuple
23452351
object. [5]_ Otherwise, *values* must be a tuple with exactly the number of

Doc/library/typing.rst

Lines changed: 15 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,25 @@
2323

2424
--------------
2525

26-
This module provides runtime support for type hints. For the original
27-
specification of the typing system, see :pep:`484`. For a simplified
28-
introduction to type hints, see :pep:`483`.
26+
This module provides runtime support for type hints.
2927

28+
Consider the function below::
3029

31-
The function below takes and returns a string and is annotated as follows::
30+
def moon_weight(earth_weight: float) -> str:
31+
return f'On the moon, you would weigh {earth_weight * 0.166} kilograms.'
3232

33-
def greeting(name: str) -> str:
34-
return 'Hello ' + name
33+
The function ``moon_weight`` takes an argument expected to be an instance of :class:`float`,
34+
as indicated by the *type hint* ``earth_weight: float``. The function is expected to
35+
return an instance of :class:`str`, as indicated by the ``-> str`` hint.
3536

36-
In the function ``greeting``, the argument ``name`` is expected to be of type
37-
:class:`str` and the return type :class:`str`. Subtypes are accepted as
38-
arguments.
37+
While type hints can be simple classes like :class:`float` or :class:`str`,
38+
they can also be more complex. The :mod:`typing` module provides a vocabulary of
39+
more advanced type hints.
3940

4041
New features are frequently added to the ``typing`` module.
4142
The `typing_extensions <https://pypi.org/project/typing-extensions/>`_ package
4243
provides backports of these new features to older versions of Python.
4344

44-
For a summary of deprecated features and a deprecation timeline, please see
45-
`Deprecation Timeline of Major Features`_.
46-
4745
.. seealso::
4846

4947
`"Typing cheat sheet" <https://mypy.readthedocs.io/en/stable/cheat_sheet_py3.html>`_
@@ -61,67 +59,11 @@ For a summary of deprecated features and a deprecation timeline, please see
6159

6260
.. _relevant-peps:
6361

64-
Relevant PEPs
65-
=============
66-
67-
Since the initial introduction of type hints in :pep:`484` and :pep:`483`, a
68-
number of PEPs have modified and enhanced Python's framework for type
69-
annotations:
70-
71-
.. raw:: html
72-
73-
<details>
74-
<summary><a style="cursor:pointer;">The full list of PEPs</a></summary>
75-
76-
* :pep:`526`: Syntax for Variable Annotations
77-
*Introducing* syntax for annotating variables outside of function
78-
definitions, and :data:`ClassVar`
79-
* :pep:`544`: Protocols: Structural subtyping (static duck typing)
80-
*Introducing* :class:`Protocol` and the
81-
:func:`@runtime_checkable<runtime_checkable>` decorator
82-
* :pep:`585`: Type Hinting Generics In Standard Collections
83-
*Introducing* :class:`types.GenericAlias` and the ability to use standard
84-
library classes as :ref:`generic types<types-genericalias>`
85-
* :pep:`586`: Literal Types
86-
*Introducing* :data:`Literal`
87-
* :pep:`589`: TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys
88-
*Introducing* :class:`TypedDict`
89-
* :pep:`591`: Adding a final qualifier to typing
90-
*Introducing* :data:`Final` and the :func:`@final<final>` decorator
91-
* :pep:`593`: Flexible function and variable annotations
92-
*Introducing* :data:`Annotated`
93-
* :pep:`604`: Allow writing union types as ``X | Y``
94-
*Introducing* :data:`types.UnionType` and the ability to use
95-
the binary-or operator ``|`` to signify a
96-
:ref:`union of types<types-union>`
97-
* :pep:`612`: Parameter Specification Variables
98-
*Introducing* :class:`ParamSpec` and :data:`Concatenate`
99-
* :pep:`613`: Explicit Type Aliases
100-
*Introducing* :data:`TypeAlias`
101-
* :pep:`646`: Variadic Generics
102-
*Introducing* :data:`TypeVarTuple`
103-
* :pep:`647`: User-Defined Type Guards
104-
*Introducing* :data:`TypeGuard`
105-
* :pep:`655`: Marking individual TypedDict items as required or potentially missing
106-
*Introducing* :data:`Required` and :data:`NotRequired`
107-
* :pep:`673`: Self type
108-
*Introducing* :data:`Self`
109-
* :pep:`675`: Arbitrary Literal String Type
110-
*Introducing* :data:`LiteralString`
111-
* :pep:`681`: Data Class Transforms
112-
*Introducing* the :func:`@dataclass_transform<dataclass_transform>` decorator
113-
* :pep:`692`: Using ``TypedDict`` for more precise ``**kwargs`` typing
114-
*Introducing* a new way of typing ``**kwargs`` with :data:`Unpack` and
115-
:data:`TypedDict`
116-
* :pep:`695`: Type Parameter Syntax
117-
*Introducing* builtin syntax for creating generic functions, classes, and type aliases.
118-
* :pep:`698`: Adding an override decorator to typing
119-
*Introducing* the :func:`@override<override>` decorator
120-
121-
.. raw:: html
122-
123-
</details>
124-
<br>
62+
Specification for the Python Type System
63+
========================================
64+
65+
The canonical, up-to-date specification of the Python type system can be
66+
found at `"Specification for the Python type system" <https://typing.readthedocs.io/en/latest/spec/index.html>`_.
12567

12668
.. _type-aliases:
12769

Doc/whatsnew/3.13.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,13 @@ asyncio
289289
forcefully close an asyncio server.
290290
(Contributed by Pierre Ossman in :gh:`113538`.)
291291

292+
* :func:`asyncio.as_completed` now returns an object that is both an
293+
:term:`asynchronous iterator` and a plain :term:`iterator` of awaitables.
294+
The awaitables yielded by asynchronous iteration include original task or
295+
future objects that were passed in, making it easier to associate results
296+
with the tasks being completed.
297+
(Contributed by Justin Arthur in :gh:`77714`.)
298+
292299
base64
293300
------
294301

@@ -806,6 +813,11 @@ Deprecated
806813
translation was not found.
807814
(Contributed by Serhiy Storchaka in :gh:`88434`.)
808815

816+
* :mod:`glob`: The undocumented :func:`!glob.glob0` and :func:`!glob.glob1`
817+
functions are deprecated. Use :func:`glob.glob` and pass a directory to its
818+
*root_dir* argument instead.
819+
(Contributed by Barney Gale in :gh:`117337`.)
820+
809821
* :mod:`http.server`: :class:`http.server.CGIHTTPRequestHandler` now emits a
810822
:exc:`DeprecationWarning` as it will be removed in 3.15. Process-based CGI
811823
HTTP servers have been out of favor for a very long time. This code was

0 commit comments

Comments
 (0)