Skip to content

Commit 5019628

Browse files
committed
Add a whatsnew entry.
1 parent 92e4c77 commit 5019628

1 file changed

Lines changed: 49 additions & 0 deletions

File tree

Doc/whatsnew/3.15.rst

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ Summary -- Release highlights
8787
<whatsnew315-pybyteswriter>`
8888
* :pep:`803`: :ref:`Stable ABI for Free-Threaded Builds <whatsnew315-abi3t>`
8989
* :pep:`831`: :ref:`Frame pointers everywhere <whatsnew315-frame-pointers>`
90+
* :pep:`828`: :ref:`'yield from' in async generators <whatsnew315-async-yield-from>`
9091
* :ref:`The JIT compiler has been significantly upgraded <whatsnew315-jit>`
9192
* :ref:`Improved error messages <whatsnew315-improved-error-messages>`
9293
* :ref:`The official Windows 64-bit binaries now use the tail-calling interpreter
@@ -447,6 +448,54 @@ If not using a build tool -- or when writing such a tool -- you can select
447448
``abi3t`` by setting the macro :c:macro:`!Py_TARGET_ABI3T` as discussed
448449
in :ref:`abi3-compiling`.
449450

451+
.. _whatsnew315-async-yield-from:
452+
453+
:pep:`828`: Supporting ``yield from`` in asynchronous generators
454+
----------------------------------------------------------------
455+
456+
Use of the :keyword:`yield from <yield>` construct and the :keyword:`return`
457+
statement with a non-``None`` value is now allowed in an
458+
:term:`asynchronous generator function <asynchronous generator>`. For example,
459+
the following code would previously raise a :class:`SyntaxError`:
460+
461+
.. code-block:: python
462+
463+
async def agenerator():
464+
yield 1
465+
yield from range(2, 5) # Now allowed!
466+
return 5 # Now allowed!
467+
468+
Additionally, there is a new ``async yield from`` statement to delegate to an
469+
asynchronous generator:
470+
471+
.. code-block:: python
472+
473+
async def sleepy_range(start, stop):
474+
for number in range(start, stop):
475+
await asyncio.sleep(1)
476+
yield number
477+
478+
async def agenerator():
479+
yield 1
480+
async yield from sleepy_range(2, 5)
481+
yield 5
482+
483+
484+
Similar to ``yield from``, ``async yield from`` may also be used as an expression,
485+
in which case the ``return`` of the async generator is used.
486+
487+
For example:
488+
489+
.. code-block:: python
490+
491+
async def asubgenerator():
492+
yield 1
493+
yield 2
494+
return 3
495+
496+
async def agenerator():
497+
value = async yield from asubgenerator()
498+
print(value) # 3
450499
451500
.. _whatsnew315-improved-error-messages:
452501

0 commit comments

Comments
 (0)