Skip to content

gh-148736: Use ag_frame when walking async generators in asyncio.graph#148737

Open
rajkripal wants to merge 1 commit intopython:mainfrom
rajkripal:fix/asyncio-graph-ag-frame
Open

gh-148736: Use ag_frame when walking async generators in asyncio.graph#148737
rajkripal wants to merge 1 commit intopython:mainfrom
rajkripal:fix/asyncio-graph-ag-frame

Conversation

@rajkripal
Copy link
Copy Markdown

Fixes gh-148736.

One-line correction: the ag_await branch of _build_graph_for_future was using cr_frame instead of ag_frame. Added a regression test that constructs a minimal ag_await chain and exercises the walker directly.

@python-cla-bot
Copy link
Copy Markdown

python-cla-bot bot commented Apr 18, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

…o.graph

_build_graph_for_future appended FrameCallGraphEntry(coro.cr_frame) in
the ag_await branch; async generators expose ag_frame. The line is
unreachable via standard async-for (async_generator_asend has neither
cr_await nor ag_await) but is reachable from duck-typed chains.
@rajkripal rajkripal force-pushed the fix/asyncio-graph-ag-frame branch from 6cb5387 to 9028577 Compare April 18, 2026 21:02

loop = asyncio.new_event_loop()
try:
fut = loop.create_future()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you should use a task and a real agen

@rajkripal
Copy link
Copy Markdown
Author

Fair point on the sentinels. Worth flagging: the ag_await branch on line 65 is effectively dead code. async_generator.__anext__() returns an async_generator_asend, which exposes neither cr_await nor ag_await, so the walker hits else: break and never reaches it. A real-async-gen test would pass before and after the patch.

Duck-typed stubs are the only way to drive that branch. Open to closing this if dead-code cleanup isn't worth the churn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio.capture_call_graph: AttributeError walking async-generator ag_await chain

2 participants