Repository navigation
gh-157361: Implement anext() in Python instead of C - #157362
Merged
Merged
Conversation
Remove the C implementation of the anext() builtin and the anext_awaitable helper type. Instead, compile a small Python source at interpreter startup and copy the resulting anext() function into the builtins dict. The Python version keeps the C semantics: __anext__ is looked up on the type and called eagerly, the one-argument form returns the awaitable unchanged, and the two-argument form wraps it in a coroutine that returns the default on StopAsyncIteration. The source is executed from pycore_init_builtins() rather than _PyBuiltin_Init(), since running bytecode requires the interpreter's common constants, which are only set up after the builtins module is created.
picnixz
reviewed
Sep 12, 2026
picnixz
reviewed
Sep 12, 2026
picnixz
reviewed
Sep 12, 2026
kumaraditya303
force-pushed
the
anext-in-python
branch
from
September 13, 2026 04:06
5a5f663 to
52befa6
Compare
kumaraditya303
marked this pull request as ready for review
September 13, 2026 04:16
kumaraditya303
requested review from
1st1,
AA-Turner,
FFY00,
ZeroIntensity,
asvetlov,
brettcannon,
emmatyping,
ericsnowcurrently,
erlend-aasland,
itamaro,
ncoghlan,
warsaw and
willingc
as code owners
September 13, 2026 04:16
|
🤖 New build scheduled with the buildbot fleet by @kumaraditya303 for commit 9db7837 🤖 Results will be shown at: https://buildbot.python.org/all/#/grid?branch=refs%2Fpull%2F157362%2Fmerge If you want to schedule another build, you need to add the 🔨 test-with-buildbots label again. |
picnixz
reviewed
Sep 13, 2026
brettcannon
removed their request for review
September 14, 2026 22:18
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Contributor
Author
|
I'm merging this to start working on implementing |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Remove the C implementation of the
anext()builtin and theanext_awaitablehelper type. A_pybuiltinsmodule is created with the implementation and that is frozen into the interpreter using the existing freeze infrastructure.The Python version keeps the C semantics:
__anext__is looked up on the type and called eagerly, the one-argument form returns the awaitable unchanged, and the two-argument form wraps it in a coroutine that returns the default onStopAsyncIteration.I'll implement
aitersimilarly in a followup.anextandaiterin pure Python #157361