`types._GeneratorWrapper` is no longer consistent with `types.GeneratorType`/`types.CoroutineType`
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug report
Bug description:
types.coroutine() uses _GeneratorWrapper as a wrapper for generator iterators in cases where the callable object is not a user-defined function (but is, for example, a generator function compiled via Cython/Nuitka). However, the implementation has not been updated for 11 years and therefore does not provide certain properties, such as:
GeneratorType.gi_suspended(Python ≥3.11, python/cpython#30633)CoroutineType.cr_suspended(Python ≥3.11, python/cpython#30633)CoroutineType.cr_origin(Python ≥3.7, python/cpython#5250)
As a result, the objects returned by the new function do not look exactly like types.GeneratorType/types.CoroutineType, which in particular makes them incompatible with the inspect.getgeneratorstate() and inspect.getcoroutinestate() functions:
>>> from inspect import getcoroutinestate, getgeneratorstate
>>> from types import coroutine
>>> def generator_function():
... return
... yield # generator definition
>>> @coroutine
... def coroutine_function():
... return generator_function()
>>> gencoro = coroutine_function()
>>> getgeneratorstate(gencoro)
Traceback (most recent call last):
AttributeError: '_GeneratorWrapper' object has no attribute 'gi_suspended'
>>> getcoroutinestate(gencoro)
Traceback (most recent call last):
AttributeError: '_GeneratorWrapper' object has no attribute 'cr_suspended'
Interestingly, there was already an attempt to add *_suspended in #133373 (see https://github.com/python/cpython/issues/133372#issuecomment-2849166854), but the PR was closed in favor of removing the TODO comment, and this side issue was apparently overlooked.
Related: cython/cython#7448.
CPython versions tested on:
3.11, 3.12, 3.13, 3.14
Operating systems tested on:
Linux
Linked PRs
- gh-143609
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
Lib/types.py の255-289行目から始め、続いて inspect.getgeneratorstate() と inspect.getcoroutinestate() を調べます。これらはレポートで影響を受けるエントリポイントとして特定されています。wrapper が公開する属性を GeneratorType および CoroutineType と比較します。完了とは、ラップされたオブジェクトに対して両方の inspect 関数が機能し、一覧にある一時停止およびオリジンのプロパティが一貫していることを意味します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- backend
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 28/100