gh-157361: Implement anext() in Python instead of C - #157362
Draft
kumaraditya303 wants to merge 3 commits into
Draft
gh-157361: Implement anext() in Python instead of C#157362kumaraditya303 wants to merge 3 commits into
anext() in Python instead of C#157362kumaraditya303 wants to merge 3 commits into
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.
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. Instead, compile a small Python source at interpreter startup and copy the resultinganext()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 onStopAsyncIteration.I'll implement
aitersimilarly in a followup.anextandaiterin pure Python #157361