Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
Description
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, bpo-46409: Make generators in bytecode #30633)CoroutineType.cr_suspended(Python ≥3.11, bpo-46409: Make generators in bytecode #30633)CoroutineType.cr_origin(Python ≥3.7, bpo-32591: Add native coroutine origin tracking #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:
>>>frominspectimportgetcoroutinestate, getgeneratorstate>>>fromtypesimportcoroutine>>>defgenerator_function(): ... return ... yield# generator definition>>> @coroutine ... defcoroutine_function(): ... returngenerator_function() >>>gencoro=coroutine_function() >>>getgeneratorstate(gencoro) Traceback (mostrecentcalllast): AttributeError: '_GeneratorWrapper'objecthasnoattribute'gi_suspended'>>>getcoroutinestate(gencoro) Traceback (mostrecentcalllast): AttributeError: '_GeneratorWrapper'objecthasnoattribute'cr_suspended'Interestingly, there was already an attempt to add *_suspended in #133373 (see #133372 (comment)), 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