Skip to content

Commit 59e07f7

Browse files
committed
Some revisions.
1 parent aaf2b0d commit 59e07f7

1 file changed

Lines changed: 23 additions & 14 deletions

File tree

peps/pep-0828.rst

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@ If no argument is supplied, ``value`` will be ``None``.
153153
``return`` statements inside asynchronous generators
154154
----------------------------------------------------
155155

156-
In an asynchronous generator, the statement ``return expression`` is
157-
roughly equivalent to ``raise StopAsyncIteration(expression)``. However,
156+
In the body of an asynchronous generator function, the statement
157+
``return expression`` is roughly equivalent to
158+
``raise StopAsyncIteration(expression)``. However, similar to implicit
159+
``StopIteration`` exceptions raised inside of synchronous generators,
158160
the exception cannot be caught in the body of the asynchronous generator.
159161

160162

@@ -241,6 +243,12 @@ Backwards Compatibility
241243

242244
This PEP introduces a backwards-compatible syntax change.
243245

246+
The addition of the ``value`` attribute to :exc:`StopAsyncIteration` is a
247+
minor semantic change to an existing builtin exception, but is unlikely
248+
to affect existing code in practice, as it mirrors the existing ``value``
249+
attribute on :exc:`StopIteration` and does not affect any other behavior
250+
on ``StopAsyncIteration`` or the asynchronous iterator protocol.
251+
244252

245253
Security Implications
246254
=====================
@@ -257,7 +265,7 @@ intends to be very intuitive; users should be able to naturally reach
257265
for ``async yield from`` given their own background knowledge about generators
258266
in Python. This can be encouraged further by suggesting
259267
``async yield from`` in the error message when a user attempts to use
260-
``yield from`` in a synchronous generator.
268+
``yield from`` in an asynchronous generator.
261269

262270

263271
Reference Implementation
@@ -319,10 +327,11 @@ to the caller:
319327
320328
Now, imagine that the developer wants to add an ``await`` call somewhere in
321329
this function; the ``yield from something_else()`` statement would suddenly
322-
become invalid. With the current proposal, the existence of ``async yield from``
323-
(which would ideally be included in the error message) would make it much
324-
clearer that ``something_else`` must also be asynchronous in order to use it
325-
in the function.
330+
become a runtime :class:`TypeError` (as opposed to a compile-time
331+
:class:`SyntaxError`). With the current proposal, the existence of
332+
``async yield from`` (which would ideally be included in the error message)
333+
would make it much clearer that ``something_else`` must also be asynchronous
334+
in order to delegate to it.
326335

327336
Finally, this would preclude the introduction of support for synchronous
328337
subgenerator delegation inside asynchronous generators (see
@@ -337,7 +346,7 @@ are solvable given time.
337346
-----------------------------------------------------
338347

339348
As an alternate solution to the verbosity of ``async yield from``, some have
340-
suggested using spellings such as ``async from`` in order to cut down the
349+
suggested using spellings such as ``async from`` in order to cut down on the
341350
verbosity. Unfortunately, changes in the spelling will likely hurt the
342351
readability of the syntax as a whole.
343352

@@ -375,11 +384,11 @@ generators:
375384

376385
.. code-block:: python
377386
378-
async def agen():
379-
async with asyncio.timeout(3):
380-
# If the timeout fails, then an asyncio.TimeoutError would be raised
381-
# in a *synchronous* generator!
382-
yield from subgen()
387+
async def agen():
388+
async with asyncio.timeout(3):
389+
# If the timeout fails, then an asyncio.TimeoutError would be raised
390+
# in a *synchronous* generator!
391+
yield from subgen()
383392
384393
385394
To quote Brandt Bucher (paraphrased):
@@ -408,7 +417,7 @@ collecting outside opinions about the design and implementation.
408417
Change History
409418
==============
410419

411-
- 22-May-2026
420+
- 26-May-2026
412421

413422
- Removed support for delegating to a synchronous subgenerator (via
414423
a plain ``yield from``).

0 commit comments

Comments
 (0)