-
-
Notifications
You must be signed in to change notification settings - Fork 33.1k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement
Description
Bug report
Bug description:
Rather than the actual value, sys.monitoring
's PY_YIELD
event passes in to the callback the internal async_generator_wrapped_value
.
I imagine this is a bug... it's inconsistent with what it does for non-async generators.
import sys
import types
import typing
import asyncio
async def gen():
yield 42
async def main():
async for _ in gen():
pass
def handle_yield(code: types.CodeType, offset: int, value: object) -> typing.Any:
if code.co_filename == __file__:
print(f"yield name={code.co_qualname} {type(value)=}")
sysmon = sys.monitoring
sysmon.use_tool_id(4, "r")
sysmon.register_callback(4, sysmon.events.PY_YIELD, handle_yield)
sysmon.set_events(4, sysmon.events.PY_YIELD)
asyncio.run(main())
This prints out:
yield name=gen type(value)=<class 'async_generator_wrapped_value'>
CPython versions tested on:
3.12, 3.13, 3.14
Operating systems tested on:
macOS, Linux
Linked PRs
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-featureA feature request or enhancementA feature request or enhancement