René's URL Explorer Experiment


Title: Fix anext awaitable ag gen by anshuman0123 · Pull Request #157035 · python/cpython · GitHub

Open Graph Title: Fix anext awaitable ag gen by anshuman0123 · Pull Request #157035 · python/cpython

X Title: Fix anext awaitable ag gen by anshuman0123 · Pull Request #157035 · python/cpython

Description: Description Fixes gh-157032. When calling anext(agen, default) with a default value, Python wraps the underlying anext() awaitable in an internal anext_awaitable instance (iterobject.c:406-410 in Objects/iterobject.c). During task call-stack inspection, _build_graph_for_future in graph.py:40-82 traverses cr_await, ag_await, and ag_gen to walk through coroutines, async generators, and generator-driving awaitables. Because anext_awaitable lacked an ag_gen attribute, traversal terminated early upon encountering anext_awaitable, losing the entire call stack inside the async generator and any child coroutines it was waiting on. This PR exposes a read-only ag_gen attribute on anext_awaitable that delegates to self.wrapped.ag_gen. ────── Changes Made: iterobject.c: • Added getter anextawaitable_getag_gen to read ag_gen from obj->wrapped. • Added anextawaitable_getsetlist and hooked it into _PyAnextAwaitable_Type.tp_getset. graph.py: • Updated the comment on ag_gen traversal to reference both gh-156980 and gh-157032. test_asyncgen.py: • Added test_async_gen_anext_default_ag_gen to verify anext(agen, default).ag_gen returns the generator, is read-only, and raises AttributeError for non-generator async iterators. test_graph.py: • Added test_stack_async_gen_anext_default testing both C and Python event loop implementations. functions.rst: • Documented the ag_gen attribute on the awaitable returned by anext(). Misc/NEWS.d/next/Library/: • Added NEWS entry for gh-157032. ────── Repro & Verification import asyncio async def deep(): await asyncio.Event().wait() async def rows(): await deep() yield 1 async def worker(): await anext(rows(), None) async def main(): t = asyncio.create_task(worker(), name='worker') await asyncio.sleep(0.05) asyncio.print_call_graph(t) t.cancel() try: await t except asyncio.CancelledError: pass asyncio.run(main()) Before: * Task(name='worker', id=0x1035c89b0) + Call stack: | File 'repro.py', line 11, in async worker() After: * Task(name='worker', id=0x244549256d0) + Call stack: | File '.../Lib/asyncio/locks.py', line 210, in async Event.wait() | File 'repro.py', line 5, in async deep() | File 'repro.py', line 8, in async generator rows() | File 'repro.py', line 12, in async worker() ────── Test Suite Results: • python -m test test_asyncgen: Passed (100%) • python -m test test_asyncio: Passed (35/35 test suites, 2,749 tests, 0 failures)

Open Graph Description: Description Fixes gh-157032. When calling anext(agen, default) with a default value, Python wraps the underlying anext() awaitable in an internal anext_awaitable instance (iterobject.c:406-410 in O...

X Description: Description Fixes gh-157032. When calling anext(agen, default) with a default value, Python wraps the underlying anext() awaitable in an internal anext_awaitable instance (iterobject.c:406-410 in O...

Opengraph URL: https://github.com/python/cpython/pull/157035

X: @github

direct link

Domain: github.com

react-profiling0
react-import-mapreact,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322
route-pattern/:user_id/:repository/pull/:id/files(.:format)
route-controllerpull_requests
route-actionfiles
fetch-noncev2:5499d119-d42a-e633-f235-5ab346835acd
current-catalog-service-hashae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b
request-idDBE4:AA9CB:6686A4:86E316:6B024AAD
html-safe-noncef096119b54098a50d0618c46b796c74f4069a0fb1fcbddba7a84736049a38da2
visitor-payloadeyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQkU0OkFBOUNCOjY2ODZBNDo4NkUzMTY6NkIwMjRBQUQiLCJ2aXNpdG9yX2lkIjoiMzkxMzUwNjY4OTMxOTU4NjQ3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9
visitor-hmac2f0ef066bb8e2decf44183612bec827b8b877cf63d549920b7d3ab5dfab3e892
hovercard-subject-tagpull_request:4456516484
github-keyboard-shortcutsrepository,pull-request-list,pull-request-conversation,pull-request-files-changed,copilot
google-site-verificationApib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I
octolytics-urlhttps://collector.github.com/github/collect
analytics-location///pull_requests/show/files
fb:app_id1401488693436528
apple-itunes-appapp-id=1477376905, app-argument=https://github.com/python/cpython/pull/157035/files
twitter:imagehttps://avatars.githubusercontent.com/u/63575217?s=400&v=4
twitter:cardsummary_large_image
og:imagehttps://avatars.githubusercontent.com/u/63575217?s=400&v=4
og:image:altDescription Fixes gh-157032. When calling anext(agen, default) with a default value, Python wraps the underlying anext() awaitable in an internal anext_awaitable instance (iterobject.c:406-410 in O...
og:site_nameGitHub
og:typeobject
hostnamegithub.com
expected-hostnamegithub.com
None87e774ee7c6b3bee0490394e4d3e57ec9dbc956f74b87ea685dc8996c1676456
turbo-cache-controlno-preview
diff-viewunified
go-importgithub.com/python/cpython git https://github.com/python/cpython.git
octolytics-dimension-user_id1525981
octolytics-dimension-user_loginpython
octolytics-dimension-repository_id81598961
octolytics-dimension-repository_nwopython/cpython
octolytics-dimension-repository_publictrue
octolytics-dimension-repository_is_forkfalse
octolytics-dimension-repository_network_root_id81598961
octolytics-dimension-repository_network_root_nwopython/cpython
turbo-body-classeslogged-out env-production page-responsive full-width
disable-turbotrue
browser-stats-urlhttps://api.github.com/_private/browser/stats
browser-errors-urlhttps://api.github.com/_private/browser/errors
release423dbb54c5e7bfecc838eb387c1435eb3d0e760d
ui-targetfull
theme-color#1e2327
color-schemelight dark

Links:

Skip to contenthttps://github.com/python/cpython/pull/157035/files#start-of-content
https://github.com/
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F157035%2Ffiles
GitHubRepository hosting, code review, and collaborationhttps://github.com/platform
CopilotAI coding agent for tasks, projects, and automated workhttps://github.com/features/copilot
ActionsCI/CD and automationhttps://github.com/features/actions
Code QualityQuality analysis, fixes, and enforcementhttps://github.com/features/code-quality
CodespacesCloud development environmentshttps://github.com/features/codespaces
Code SecurityVulnerability detection and remediationhttps://github.com/security/advanced-security/code-security
Secret ProtectionSecret scanning and leak preventionhttps://github.com/security/advanced-security/secret-protection
All Featureshttps://github.com/features
Documentationhttps://docs.github.com/en
Traininghttps://learn.github.com/skills
Certificationshttps://learn.github.com/credentials
Build with Copilothttps://github.com/features/ai
Customize Copilothttps://docs.github.com/en/copilot/how-tos/copilot-on-github/customize-copilot/customize-copilot-overview
Integrationshttps://github.com/marketplace
Trending reposhttps://github.com/trending
GitHub Sponsorshttps://github.com/open-source/sponsors
Developer articleshttps://github.com/resources/articles
ChangelogYour source for the latest features, improvements, and fixes across GitHub products, all in one place.https://github.blog/changelog/
Enterpriseshttps://github.com/enterprise
Teamhttps://github.com/team
Startupshttps://github.com/enterprise/startups
Nonprofitshttps://github.com/solutions/industry/nonprofits
Healthcarehttps://github.com/solutions/industry/healthcare
Financial serviceshttps://github.com/solutions/industry/financial-services
Manufacturinghttps://github.com/solutions/industry/manufacturing
Governmenthttps://github.com/solutions/industry/government
See all industrieshttps://github.com/solutions/industry
Why GitHubhttps://github.com/why-github
Customer Storieshttps://github.com/customer-stories
Business insightshttps://github.com/solutions/executive-insights
Trust Centerhttps://github.com/trust-center
GitHub Advanced SecurityEnterprise-grade code securityhttps://github.com/security/advanced-security
Copilot for businessEnterprise-grade AI featureshttps://github.com/features/copilot/copilot-business
Premium SupportEnterprise-grade 24/7 supporthttps://github.com/enterprise/premium-support
Documentationhttps://docs.github.com/en
Resource centerhttps://github.com/resources
Bloghttps://github.blog/
Events & webinarshttps://github.com/resources/events
Community Forumhttps://github.com/orgs/community/discussions
Customer Storieshttps://github.com/customer-stories
Integrationshttps://github.com/marketplace
Customer supporthttps://help.github.com/
Traininghttps://learn.github.com/skills
GitHub Statushttps://www.githubstatus.com/
Abouthttps://github.com/about
Partnershttps://github.com/partners
Changeloghttps://github.blog/changelog/
GitHub UniverseThe event for developers, by developers — talks, workshops, and what’s next for GitHub.https://githubuniverse.com/
Pricinghttps://github.com/pricing
Sign inhttps://github.com/login?return_to=https%3A%2F%2Fgithub.com%2Fpython%2Fcpython%2Fpull%2F157035%2Ffiles
Sign uphttps://github.com/signup?ref_cta=Sign+up&ref_loc=header+logged+out&ref_page=%2F%3Cuser-name%3E%2F%3Crepo-name%3E%2Fpull_requests%2Fshow%2Ffiles&source=header-repo&source_repo=python%2Fcpython
Reloadhttps://github.com/python/cpython/pull/157035/files
Reloadhttps://github.com/python/cpython/pull/157035/files
Reloadhttps://github.com/python/cpython/pull/157035/files
pythonhttps://github.com/python
cpythonhttps://github.com/python/cpython
Codehttps://github.com/python/cpython
Issues5k+ (5k+)https://github.com/python/cpython/issues
Pull requests2.4k (2.4k)https://github.com/python/cpython/pulls
Actionshttps://github.com/python/cpython/actions
Projectshttps://github.com/python/cpython/projects
Security and qualityhttps://github.com/python/cpython/security
Insightshttps://github.com/python/cpython/insights
Sign up for GitHub https://github.com/signup?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
terms of servicehttps://docs.github.com/terms
privacy statementhttps://docs.github.com/privacy
Sign inhttps://github.com/login?return_to=%2Fpython%2Fcpython%2Fissues%2Fnew%2Fchoose
anshuman0123https://github.com/anshuman0123
python:mainhttps://github.com/python/cpython/tree/main
anshuman0123:fix-anext-awaitable-ag-genhttps://github.com/anshuman0123/cpython/tree/fix-anext-awaitable-ag-gen
Conversation 1 https://github.com/python/cpython/pull/157035
Commits 2 https://github.com/python/cpython/pull/157035/commits
Checks 103 https://github.com/python/cpython/pull/157035/checks
Files changed https://github.com/python/cpython/pull/157035/files
Please reload this pagehttps://github.com/python/cpython/pull/157035/files
Fix anext awaitable ag gen https://github.com/python/cpython/pull/157035/files#top
Show all changes 2 commits https://github.com/python/cpython/pull/157035/files
8fdf324 gh-156980: Fix asyncio call graph truncation at async generators deadlovelll Sep 5, 2026 https://github.com/python/cpython/pull/157035/commits/8fdf324609bf69a87de237c933c67bff5b81a6e2
e85766d gh-157032: Expose ag_gen on anext_awaitable to preserve asyncio call … anshuman0123 Sep 6, 2026 https://github.com/python/cpython/pull/157035/commits/e85766db8ddfe86cf7fbcec3126a888d35c9bac4
Clear filters https://github.com/python/cpython/pull/157035/files
Please reload this pagehttps://github.com/python/cpython/pull/157035/files
Please reload this pagehttps://github.com/python/cpython/pull/157035/files
functions.rst https://github.com/python/cpython/pull/157035/files#diff-6a7a07ac473fdd76734669b1b70626ad2176011129902f6add017810f54d0439
stdtypes.rst https://github.com/python/cpython/pull/157035/files#diff-08a31a70dd1f6d97aa8dacdce77db4de04c700d9949be1af611a595186aad5b3
graph.py https://github.com/python/cpython/pull/157035/files#diff-8b5bdb2ffdd61afea57f7baf091bbef9b5b8d2b330654325591be45b8abf612d
test_asyncgen.py https://github.com/python/cpython/pull/157035/files#diff-1da5f0220b91e20c669b0e63724b978d4cf603373c850fbdc705abb2d5937f40
test_graph.py https://github.com/python/cpython/pull/157035/files#diff-be8b668d2f3d075670425801b96a54d7e8db1033442919c45278f51312b10f4a
2026-09-05-17-29-50.gh-issue-156980.W6kHva.rst https://github.com/python/cpython/pull/157035/files#diff-2ad9fe5a340079cd1b5c88cdfa6a90a8c4758ace0c80fe2f99110335aef43f2f
2026-09-06-12-00-00.gh-issue-157032.XyZ123.rst https://github.com/python/cpython/pull/157035/files#diff-0ef0d1ae4d2395ddc0c98262e09089637433c88ef2351bf12f54babf76c09fde
genobject.c https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
iterobject.c https://github.com/python/cpython/pull/157035/files#diff-e0923aa0ec18bd667c33e79ede96b408e9bca3e9e0af262028722d7f23928723
Doc/library/functions.rsthttps://github.com/python/cpython/pull/157035/files#diff-6a7a07ac473fdd76734669b1b70626ad2176011129902f6add017810f54d0439
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Doc/library/functions.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157035/files#diff-6a7a07ac473fdd76734669b1b70626ad2176011129902f6add017810f54d0439
https://github.com/python/cpython/pull/157035/files#diff-6a7a07ac473fdd76734669b1b70626ad2176011129902f6add017810f54d0439
Doc/library/stdtypes.rsthttps://github.com/python/cpython/pull/157035/files#diff-08a31a70dd1f6d97aa8dacdce77db4de04c700d9949be1af611a595186aad5b3
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Doc/library/stdtypes.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157035/files#diff-08a31a70dd1f6d97aa8dacdce77db4de04c700d9949be1af611a595186aad5b3
https://github.com/python/cpython/pull/157035/files#diff-08a31a70dd1f6d97aa8dacdce77db4de04c700d9949be1af611a595186aad5b3
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L376
Lib/asyncio/graph.pyhttps://github.com/python/cpython/pull/157035/files#diff-8b5bdb2ffdd61afea57f7baf091bbef9b5b8d2b330654325591be45b8abf612d
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Lib/asyncio/graph.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157035/files#diff-8b5bdb2ffdd61afea57f7baf091bbef9b5b8d2b330654325591be45b8abf612d
https://github.com/python/cpython/pull/157035/files#diff-8b5bdb2ffdd61afea57f7baf091bbef9b5b8d2b330654325591be45b8abf612d
Lib/test/test_asyncgen.pyhttps://github.com/python/cpython/pull/157035/files#diff-1da5f0220b91e20c669b0e63724b978d4cf603373c850fbdc705abb2d5937f40
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Lib/test/test_asyncgen.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157035/files#diff-1da5f0220b91e20c669b0e63724b978d4cf603373c850fbdc705abb2d5937f40
https://github.com/python/cpython/pull/157035/files#diff-1da5f0220b91e20c669b0e63724b978d4cf603373c850fbdc705abb2d5937f40
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L377
Lib/test/test_asyncio/test_graph.pyhttps://github.com/python/cpython/pull/157035/files#diff-be8b668d2f3d075670425801b96a54d7e8db1033442919c45278f51312b10f4a
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Lib/test/test_asyncio/test_graph.py
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157035/files#diff-be8b668d2f3d075670425801b96a54d7e8db1033442919c45278f51312b10f4a
https://github.com/python/cpython/pull/157035/files#diff-be8b668d2f3d075670425801b96a54d7e8db1033442919c45278f51312b10f4a
Misc/NEWS.d/next/Library/2026-09-05-17-29-50.gh-issue-156980.W6kHva.rsthttps://github.com/python/cpython/pull/157035/files#diff-2ad9fe5a340079cd1b5c88cdfa6a90a8c4758ace0c80fe2f99110335aef43f2f
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Misc/NEWS.d/next/Library/2026-09-05-17-29-50.gh-issue-156980.W6kHva.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
Misc/NEWS.d/next/Library/2026-09-06-12-00-00.gh-issue-157032.XyZ123.rsthttps://github.com/python/cpython/pull/157035/files#diff-0ef0d1ae4d2395ddc0c98262e09089637433c88ef2351bf12f54babf76c09fde
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Misc/NEWS.d/next/Library/2026-09-06-12-00-00.gh-issue-157032.XyZ123.rst
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
https://github.com/python/cpython/blob/main/.github/CODEOWNERS#L214
Objects/genobject.chttps://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Objects/genobject.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
https://github.com/python/cpython/pull/157035/files#diff-2a0c449b68605ebd0872fd232e60ce7e838a77782a6d2e364764f99514fb508a
Objects/iterobject.chttps://github.com/python/cpython/pull/157035/files#diff-e0923aa0ec18bd667c33e79ede96b408e9bca3e9e0af262028722d7f23928723
View file https://github.com/anshuman0123/cpython/blob/e85766db8ddfe86cf7fbcec3126a888d35c9bac4/Objects/iterobject.c
Open in desktop https://desktop.github.com
https://github.co/hiddenchars
https://github.com/python/cpython/pull/157035/{{ revealButtonHref }}
https://github.com/python/cpython/pull/157035/files#diff-e0923aa0ec18bd667c33e79ede96b408e9bca3e9e0af262028722d7f23928723
https://github.com/python/cpython/pull/157035/files#diff-e0923aa0ec18bd667c33e79ede96b408e9bca3e9e0af262028722d7f23928723
https://github.com/python/cpython/pull/157035/files#diff-e0923aa0ec18bd667c33e79ede96b408e9bca3e9e0af262028722d7f23928723
https://github.com/python/cpython/pull/157035/files#diff-e0923aa0ec18bd667c33e79ede96b408e9bca3e9e0af262028722d7f23928723
Please reload this pagehttps://github.com/python/cpython/pull/157035/files
https://github.com
Termshttps://docs.github.com/site-policy/github-terms/github-terms-of-service
Privacyhttps://docs.github.com/site-policy/privacy-policies/github-privacy-statement
Securityhttps://github.com/security
Statushttps://www.githubstatus.com/
Communityhttps://github.community/
Docshttps://docs.github.com/
Contacthttps://support.github.com?tags=dotcom-footer

Viewport: width=device-width


URLs of crawlers that visited me.