Title: `types._GeneratorWrapper` is no longer consistent with `types.GeneratorType`/`types.CoroutineType` · Issue #143552 · python/cpython · GitHub
Open Graph Title: `types._GeneratorWrapper` is no longer consistent with `types.GeneratorType`/`types.CoroutineType` · Issue #143552 · python/cpython
X Title: `types._GeneratorWrapper` is no longer consistent with `types.GeneratorType`/`types.CoroutineType` · Issue #143552 · python/cpython
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/Nu...
Open Graph 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 g...
X 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 g...
Opengraph URL: https://github.com/python/cpython/issues/143552
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"`types._GeneratorWrapper` is no longer consistent with `types.GeneratorType`/`types.CoroutineType`","articleBody":"# Bug report\n\n### Bug description:\n\n[`types.coroutine()`](https://docs.python.org/3/library/types.html#types.coroutine) uses [`_GeneratorWrapper`](https://github.com/python/cpython/blob/8f59fbb082a4d64619aeededc47b3b45212d2341/Lib/types.py#L255-L289) 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:\n\n* `GeneratorType.gi_suspended` (Python ≥3.11, python/cpython#30633)\n* `CoroutineType.cr_suspended` (Python ≥3.11, python/cpython#30633)\n* `CoroutineType.cr_origin` (Python ≥3.7, python/cpython#5250)\n\nAs a result, the objects returned by the new function do not look exactly like [`types.GeneratorType`](https://docs.python.org/3/library/types.html#types.GeneratorType)/[`types.CoroutineType`](https://docs.python.org/3/library/types.html#types.CoroutineType), which in particular makes them incompatible with the [`inspect.getgeneratorstate()`](https://docs.python.org/3/library/inspect.html#inspect.getgeneratorstate) and [`inspect.getcoroutinestate()`](https://docs.python.org/3/library/inspect.html#inspect.getcoroutinestate) functions:\n\n```python\n\u003e\u003e\u003e from inspect import getcoroutinestate, getgeneratorstate\n\u003e\u003e\u003e from types import coroutine\n\u003e\u003e\u003e def generator_function():\n... return\n... yield # generator definition\n\u003e\u003e\u003e @coroutine\n... def coroutine_function():\n... return generator_function()\n\u003e\u003e\u003e gencoro = coroutine_function()\n\u003e\u003e\u003e getgeneratorstate(gencoro)\nTraceback (most recent call last):\nAttributeError: '_GeneratorWrapper' object has no attribute 'gi_suspended'\n\u003e\u003e\u003e getcoroutinestate(gencoro)\nTraceback (most recent call last):\nAttributeError: '_GeneratorWrapper' object has no attribute 'cr_suspended'\n```\n\nInterestingly, 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.\n\nRelated: cython/cython#7448.\n\n### CPython versions tested on:\n\n3.11, 3.12, 3.13, 3.14\n\n### Operating systems tested on:\n\nLinux\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-143609\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/x42005e1f","@type":"Person","name":"x42005e1f"},"datePublished":"2026-01-08T09:05:12.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/143552/cpython/issues/143552"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:bd86f9b6-15bd-c1a6-cc7f-ff3d99d662a2 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AFB6:1E4FEF:32BD91B:4234AAA:696B8C3F |
| html-safe-nonce | f9509ac9baab5c2900994ae63456956eca1362323314f1936fe680cadb80bc20 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBRkI2OjFFNEZFRjozMkJEOTFCOjQyMzRBQUE6Njk2QjhDM0YiLCJ2aXNpdG9yX2lkIjoiNjA4MzYwMzE2NDAxMjcxMDk3NiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 17096196b0910622f137ebc2109d6574d4e1ff70999c38eddb9bdc7e7aa2c4fa |
| hovercard-subject-tag | issue:3792026640 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/143552/issue_layout |
| twitter:image | https://opengraph.githubassets.com/114590e96a23c9fcfdb49fa22622e29ce50e653b47d5d7d4b5a2ff2a4a37be67/python/cpython/issues/143552 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/114590e96a23c9fcfdb49fa22622e29ce50e653b47d5d7d4b5a2ff2a4a37be67/python/cpython/issues/143552 |
| og:image:alt | 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 g... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | x42005e1f |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f99f7c1d70f01da5b93e5ca90303359738944d8ab470e396496262c66e60b8d |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 82560a55c6b2054555076f46e683151ee28a19bc |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width