GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-155126: Implement PEP 828 by ZeroIntensity · Pull Request #155127 · python/cpython

Conversation

@ZeroIntensity

@ZeroIntensity ZeroIntensity commented Aug 3, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member
  • Issue: Implement PEP 828 -- Supporting 'yield from' in asynchronous generators #155126

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

johnslavik reacted with rocket emoji
All reactions
  • 🚀 1 reaction
ZeroIntensity and others added 3 commits August 3, 2026 12:11
@ZeroIntensity @johnslavik
Pull in the reference implementation.
0339a33
Co-authored-by: Bartosz Sławecki <[email protected]>
@ZeroIntensity
Add tests and whatnot.
c6d0df2
@ZeroIntensity
Add blurb.
6a89191
@ZeroIntensity
ZeroIntensity requested review from AA-Turner, iritkatriel, markshannon and willingc as code owners August 3, 2026 16:30
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 3, 2026
@bedevere-app bedevere-app Bot mentioned this pull request Aug 3, 2026
Implement PEP 828 -- Supporting 'yield from' in asynchronous generators #155126
Open
@ZeroIntensity
Fix versionadded marker.
8a7b7b0
@read-the-docs-community

read-the-docs-community Bot commented Aug 3, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #35362751 | 📁 Comparing 6daaafc against main (1617cbe)

  🔍 Preview build  

423 files changed · + 10 added · ± 413 modified

+ Added

  • builtins/constants.html
  • builtins/exceptions.html
  • builtins/functions.html
  • builtins/index.html
  • builtins/stdtypes.html
  • builtins/threadsafety.html
  • builtins/time-complexity.html
  • c-api/pyexpat.html
  • library/time-complexity.html
  • library/tkinter.dialogs.html

± Modified

  • glossary.html
  • index.html
  • license.html
  • py-modindex.html
  • _static/tachyon-example-heatmap.html
  • c-api/arg.html
  • c-api/bool.html
  • c-api/buffer.html
  • c-api/bytearray.html
  • c-api/bytes.html
  • and 403 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity
Regen frozenmain test.
1d62419
@ZeroIntensity
ZeroIntensity requested a review from ericsnowcurrently as a code owner August 3, 2026 16:59
@ZeroIntensity

ZeroIntensity commented Aug 3, 2026

Copy link
Copy Markdown
Member Author

cc @1st1

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity
Remove remnants of old proposal.
c1ac461
@johnslavik
johnslavik requested a review from 1st1 August 4, 2026 13:29
ZeroIntensity added 3 commits August 5, 2026 19:44
@ZeroIntensity
Merge branch 'main' into pep-828/implementation
17aee3e
@ZeroIntensity
Merge branch 'main' of https://github.com/python/cpython into pep-828…
c1b2087
…/implementation
@ZeroIntensity
Rename internal function.
1bec377
@ZeroIntensity
ZeroIntensity requested a review from johnslavik August 19, 2026 12:51
johnslavik
johnslavik reviewed Aug 30, 2026
View reviewed changes
Comment thread Doc/reference/expressions.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

@ZeroIntensity @johnslavik
Update Doc/reference/expressions.rst
a699187
Co-authored-by: Bartosz Sławecki <[email protected]>
@johnslavik johnslavik mentioned this pull request Sep 2, 2026
gh-128404: Run TestGetAsyncGenState without asyncio #156808
Open
graingert
graingert reviewed Sep 2, 2026
View reviewed changes
Comment thread Lib/test/test_yield_from_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

ZeroIntensity and others added 3 commits September 2, 2026 20:39
@ZeroIntensity @graingert
Update Lib/test/test_yield_from_async.py
b57d744
Co-authored-by: Thomas Grainger <[email protected]>
@ZeroIntensity
Merge branch 'main' of https://github.com/python/cpython into pep-828…
810e01f
…/implementation
@ZeroIntensity
Merge branch 'main' of https://github.com/python/cpython into pep-828…
9b10752
…/implementation
@bedevere-app bedevere-app Bot added the type-feature A feature request or enhancement label Oct 12, 2026
ZeroIntensity and others added 2 commits October 19, 2026 11:52
@ZeroIntensity
Merge branch 'main' of https://github.com/python/cpython into pep-828…
1037bed
…/implementation
@1st1
Fix NULL deref in async yield from cleanup
2a44069
Treat a deleted `StopAsyncIteration.value` as `None` when handling
delegated iterator exhaustion.

Add a regression test covering immediate exhaustion and exhaustion
after yielding an item.
1st1
1st1 reviewed Oct 19, 2026
View reviewed changes
Comment thread Objects/genobject.c Outdated
// this was called from athrow(). This broke some tests/expected behavior
// for yield from in asyncgens. Removing the parameter didn't seem to cause
// any new test failures, nor could I reproduce any different behavior
// when experimenting with it, but we need to be careful.

@1st1 1st1 Oct 19, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Neither configuration is correct. Removing the flag breaks asynchronous cleanup; restoring it fixes that case but breaks the required close semantics for GeneratorExit.

I rebuilt and tested both configurations, restoring the original flag plumbing from main: gen_throw() passes 1, the initial aclose()/athrow() calls pass 0, and recursive calls preserve the flag.

Case Current branch, flag removed Flag restored
Delegate’s cleanup completes synchronously Works Works
Delegate’s cleanup suspends during aclose() Fails with RuntimeError; cleanup incomplete Works
Delegate’s cleanup suspends during athrow(GeneratorExit) Same failure Works
Delegate suppresses GeneratorExit during outer athrow(GeneratorExit) Correctly reraises the outer exception Incorrectly allows delegation to finish normally
Delegate yields an item while handling GeneratorExit Correctly raises RuntimeError Outer athrow() incorrectly returns that item
Delegate raises its own GeneratorExit during closing Preserves expected outer exception identity Identity test fails
Ordinary async generator’s own cleanup awaits Works Works
Custom async iterator implements aclose()/athrow() Methods skipped Methods skipped

The missing case in the tests is cleanup that actually suspends. This reproduces the current branch’s problem:

import asyncio

async def inner():
    try:
        yield 1
    finally:
        await asyncio.sleep(0)
        print("cleanup completed")

async def outer(sub):
    yield from sub

async def main():
    sub = inner()
    gen = outer(sub)
    await anext(gen)
    await gen.aclose()

asyncio.run(main())

Currently, aclose() raises:

RuntimeError: async generator ignored GeneratorExit

The cleanup never reaches the print. With the flag restored, cleanup completes and aclose() succeeds.

The cause is gen_close_iter() (Objects/genobject.c:427): the PR adds async generators to the branch that calls synchronous gen_close(). When cleanup suspends at an await, gen_close() treats the suspension as an illegal yield and raises RuntimeError.

Restoring the flag only exchanges one problem for another. It makes _gen_throw() forward GeneratorExit into the delegate. But async delegation must await the delegate’s aclose() and then reraise the original exception. Forwarding through throw lets the delegate suppress the exception or yield another item. That distinction is explicit in PEP 828’s reference expansion.

The custom iterator failures expose the same underlying mismatch: the current helpers look for synchronous .close() and .throw(), rather than calling and awaiting .aclose() and .athrow(). I confirmed this against a Python implementation of the PEP’s expansion; the reference calls those methods, while native delegation skips them in both configurations.

The fix needs to distinguish closing an async delegate from throwing into it, and provide a resumable path for awaiting its aclose(). A boolean change alone cannot provide both behaviors. I would investigate handling this in the async delegation bytecode expansion, where the operation can suspend, rather than extending synchronous gen_close_iter().

Validation:

  • Current branch: all 285 tests pass across test_yield_from_async, test_asyncgen, test_yield_from, and test_coroutines.
  • Flag restored: 4 errors and 3 failures, all in test_yield_from_async; the other suites pass.
  • Additional probes confirm the missing cleanup and custom iterator failures above.

The source and interpreter are restored to your current implementation; the working tree is clean. The comparison probe (/private/tmp/pep828-protocol-probe.py) and delegation edge-case probe (/private/tmp/pep828-delegation-probe.py) remain available for review.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@ZeroIntensity ZeroIntensity added the sprint label Oct 19, 2026
@github-project-automation github-project-automation Bot added this to Sprint Oct 19, 2026
@github-project-automation github-project-automation Bot moved this to Todo in Sprint Oct 19, 2026
@ZeroIntensity
Handle the async close and throw protocol from codegen.
cc73475
@ZeroIntensity
ZeroIntensity requested a review from FFY00 as a code owner October 19, 2026 21:48
ZeroIntensity added 2 commits October 20, 2026 13:13
@ZeroIntensity
Add the profiling stuff.
1878954
@ZeroIntensity
Merge branch 'main' into pep-828/implementation
6daaafc
@ZeroIntensity ZeroIntensity added needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes 🔨 test-with-buildbots Test PR w/ buildbots; report in status section and removed needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes labels Oct 23, 2026
@bedevere-bot

bedevere-bot commented Oct 23, 2026

Copy link
Copy Markdown

🤖 New build scheduled with the buildbot fleet by @ZeroIntensity for commit 6daaafc 🤖

Results will be shown at:

https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F155127%2Fmerge

If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot removed the 🔨 test-with-buildbots Test PR w/ buildbots; report in status section label Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@1st1 1st1 1st1 left review comments
@graingert graingert graingert left review comments
@johnslavik johnslavik johnslavik left review comments
@iritkatriel iritkatriel Awaiting requested review from iritkatriel iritkatriel is a code owner
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner
@willingc willingc Awaiting requested review from willingc willingc is a code owner
@ericsnowcurrently ericsnowcurrently Awaiting requested review from ericsnowcurrently ericsnowcurrently is a code owner
@FFY00 FFY00 Awaiting requested review from FFY00 FFY00 is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting core review sprint type-feature A feature request or enhancement

Projects

Sprint
Status: Todo

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

5 participants

@ZeroIntensity @bedevere-bot @1st1 @graingert @johnslavik
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.