sys.monitoring `PY_YIELD` leaks internal `async_generator_wrapped_value` object
未關閉
還沒有人認領這個 Issue。
interpreter-core
type-feature
- 主要語言
- Python
- 星號
- 77.2k
- 分支
- 35.9k
- PR 合併指標
- PR 指標待擷取
描述
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
- gh-129031
貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
研究方向
首先,在受影響的 CPython 版本上執行提供的 sys.monitoring PY_YIELD 重現,並檢查 callback 對 async generators 的行為。檢視連結的 PR gh-129031,以了解目前的實作方向;當 callback 接收到 yielded value 而不是內部的 async_generator_wrapped_value 物件,且此案例有 coverage 時,即表示完成。
由索引模型根據 Issue 內容生成。
評估
- 技術堆疊
- python
- 領域
- tooling
- Issue 類型
- 缺陷
- 難度
- 3/5
- 預估耗時
- 1-2 天
- 活躍度
- 停滯
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100