Title: what's the correct type for types.coroutine decorated generators? · Issue #2907 · python/mypy · GitHub
Open Graph Title: what's the correct type for types.coroutine decorated generators? · Issue #2907 · python/mypy
X Title: what's the correct type for types.coroutine decorated generators? · Issue #2907 · python/mypy
Description: I cannot seem to get a types.coroutine decorated generator to typecheck correctly. I checked the tests out, and they seem to indicate that the right thing to do is to annotate the return as "typing.Generator", but when I do that, mypy co...
Open Graph Description: I cannot seem to get a types.coroutine decorated generator to typecheck correctly. I checked the tests out, and they seem to indicate that the right thing to do is to annotate the return as "typing...
X Description: I cannot seem to get a types.coroutine decorated generator to typecheck correctly. I checked the tests out, and they seem to indicate that the right thing to do is to annotate the return as "t...
Opengraph URL: https://github.com/python/mypy/issues/2907
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"what's the correct type for types.coroutine decorated generators?","articleBody":"I cannot seem to get a `types.coroutine` decorated generator to typecheck correctly.\r\n\r\nI checked the [tests](https://github.com/python/mypy/blob/master/test-data/unit/check-async-await.test#L400) out, and they seem to indicate that the right thing to do is to annotate the return as \"typing.Generator\", but when I do that, mypy complains that I cannot await that.\r\n\r\n`coro_example.py`:\r\n```python\r\n\"\"\"Coro typing example.\"\"\"\r\n\r\n\r\nimport types\r\nimport typing\r\n\r\n\r\nasync def await_decorated() -> None:\r\n \"\"\"Await a decorated generator.\"\"\"\r\n x = await decorated_generator()\r\n\r\n\r\n@types.coroutine\r\ndef decorated_generator() -> typing.Generator:\r\n \"\"\"Yield None.\"\"\"\r\n yield None\r\n```\r\n\r\n```\r\n> mypy coro_example.py\r\ncoro_example.py:10: error: Incompatible types in await (actual type Generator[Any, Any, Any], expected type \"Awaitable\")\r\n```\r\n\r\nI thought perhaps I was subtly mistyping something, so I copy/pasted the code from the tests ([from line 346](https://github.com/python/mypy/blob/master/test-data/unit/check-async-await.test#L346) [to line 403](https://github.com/python/mypy/blob/master/test-data/unit/check-async-await.test#L403)) and ran that, and got similar errors:\r\n\r\n```\r\n> mypy mypy_example.py\r\nmypy_example.py:45: error: \"yield from\" can't be applied to Awaitable[int]\r\nmypy_example.py:47: error: \"yield from\" can't be applied to AwaitableGenerator[Any, Any, int, Awaitable[int]]\r\nmypy_example.py:49: error: \"yield from\" can't be applied to \"Aw\"\r\nmypy_example.py:53: error: Incompatible types in await (actual type Generator[str, None, int], expected type \"Awaitable\")\r\nmypy_example.py:57: error: Incompatible types in await (actual type \"It\", expected type \"Awaitable\")\r\n``` \r\n\r\nIf I type the generator as a `typing.Awaitable` instead, mypy tells me I have to type the generator as a generator or one of its supertypes.\r\n\r\nI've tried this with python 3.6 and the latest github and pip versions:\r\n* python 3.6.0\r\n* mypy `mypy (0.480.dev0)` (installed via `pip install git+https://github.com/python/mypy`)\r\n* mypy `mypy (0.471)` (installed via `pip install mypy`)\r\n\r\nAm I doing it wrong, or is there a bug?","author":{"url":"https://github.com/toejough","@type":"Person","name":"toejough"},"datePublished":"2017-02-25T19:54:00Z","url":"https://github.com/python/mypy/issues/2907"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| 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:ae886ec9-2728-005b-ae16-9b44af6f6b09 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | AC3E:1DA187:29BA7A4:36AF7F6:6B000A41 |
| html-safe-nonce | 7606a12c58c8106f5bbd0f8ad9cc60783d73b41079dcc595032cf3ae886ff036 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBQzNFOjFEQTE4NzoyOUJBN0E0OjM2QUY3RjY6NkIwMDBBNDEiLCJ2aXNpdG9yX2lkIjoiNjkyNDQyNDMxMTY2NzE2NTc2MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f31ca0ec8585c8f9f8351a93b0efabb2558e76084033aaf79d952dda1cdcc8db |
| hovercard-subject-tag | issue:210257528 |
| 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/mypy/2907/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2693e039f13bb22f824731fee3294626f58259701bdba9721e5a47a53fa21544/python/mypy/issues/2907 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2693e039f13bb22f824731fee3294626f58259701bdba9721e5a47a53fa21544/python/mypy/issues/2907 |
| og:image:alt | I cannot seem to get a types.coroutine decorated generator to typecheck correctly. I checked the tests out, and they seem to indicate that the right thing to do is to annotate the return as "typing... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | toejough |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0a0d8686a27478df474dd7415776a7a080cde8838b3cd92ea7601187572e5729 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/mypy git https://github.com/python/mypy.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 7053637 |
| octolytics-dimension-repository_nwo | python/mypy |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 7053637 |
| octolytics-dimension-repository_network_root_nwo | python/mypy |
| 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 | 16a11879678aaf97e2a42c33ee70830aa084fa37 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width