Title: Clarification: return type for asyncio.gather()? · Issue #3243 · python/typeshed · GitHub
Open Graph Title: Clarification: return type for asyncio.gather()? · Issue #3243 · python/typeshed
X Title: Clarification: return type for asyncio.gather()? · Issue #3243 · python/typeshed
Description: I've come across a source of confusion for asyncio.gather(). It may very well be user error rather than an incorrect annotation. (Motivated by this Stack Overflow post.) The annotation return types for gather() are Future[Tuple[_T1]], Fu...
Open Graph Description: I've come across a source of confusion for asyncio.gather(). It may very well be user error rather than an incorrect annotation. (Motivated by this Stack Overflow post.) The annotation return types...
X Description: I've come across a source of confusion for asyncio.gather(). It may very well be user error rather than an incorrect annotation. (Motivated by this Stack Overflow post.) The annotation return t...
Opengraph URL: https://github.com/python/typeshed/issues/3243
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Clarification: return type for asyncio.gather()?","articleBody":"I've come across a source of confusion for `asyncio.gather()`. It may very well be user error rather than an incorrect annotation. (Motivated by [this](https://stackoverflow.com/q/57963212/7954504) Stack Overflow post.)\r\n\r\nThe [annotation](https://github.com/python/typeshed/blob/0602840cc2df1f67805f8ab62f4aa777e566cfc6/stdlib/3/asyncio/tasks.pyi#L31) return types for `gather()` are `Future[Tuple[_T1]]`, `Future[Tuple[_T1, _T2]]`, and so on.\r\n\r\nHowever, the result of `return await asyncio.gather(*tasks)` is `List`. I.e.:\r\n\r\n```python\r\nimport asyncio\r\nfrom typing import List\r\n\r\nasync def foo(x) -> int:\r\n await asyncio.sleep(x / 2)\r\n return x\r\n\r\nasync def main() -> List[int]:\r\n return await asyncio.gather(*(foo(i) for i in (1, 2, 3)))\r\n\r\nif __name__ == \"__main__\":\r\n print(asyncio.run(main()))\r\n```\r\n\r\nThis runs find, printing `[1, 2, 3]`; `await asyncio.gather()` produces a `List[int]`.\r\n\r\nHowever, mypy complains that:\r\n\r\n> mypytest.py:9: error: Incompatible types in assignment (expression has type \"Tuple[Any, ...]\", variable has type \"List[int]\")\r\n\r\nWhy does this ambiguity exist? How can I provide a correct type hint for `async def main()`?\r\n\r\n----\r\n\r\nI'm looking at typeshed master branch as of 0602840 fyi + mypy 0.720.","author":{"url":"https://github.com/bsolomon1124","@type":"Person","name":"bsolomon1124"},"datePublished":"2019-09-18T17:00:26Z","url":"https://github.com/python/typeshed/issues/3243"}
| 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:6158d108-fe9c-e1ea-9b29-8408b7697ad5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DFF6:3E1398:1C7748:268A1D:6B002146 |
| html-safe-nonce | c5c0353f9cf965e8d2adf6cf3789a2cbff221d336238d3f7f2fc5b72e13408e3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJERkY2OjNFMTM5ODoxQzc3NDg6MjY4QTFEOjZCMDAyMTQ2IiwidmlzaXRvcl9pZCI6IjMwMjg1NTU3OTIxMDcxODQ0NTQiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | afda9a5204282bfb52796d3b1e9433056bcc0633bf9fe465445273a2046d4f4d |
| hovercard-subject-tag | issue:495346455 |
| 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/typeshed/3243/issue_layout |
| twitter:image | https://opengraph.githubassets.com/127318b4dad17897d660842ee07e605d7add40fe1d94424c4986c5a4eaf27bee/python/typeshed/issues/3243 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/127318b4dad17897d660842ee07e605d7add40fe1d94424c4986c5a4eaf27bee/python/typeshed/issues/3243 |
| og:image:alt | I've come across a source of confusion for asyncio.gather(). It may very well be user error rather than an incorrect annotation. (Motivated by this Stack Overflow post.) The annotation return types... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | bsolomon1124 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 4eb4cba0d69f045374ac15de9666d22b0961e1d555cc3824f36b7734c00c78e0 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/typeshed git https://github.com/python/typeshed.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 31696383 |
| octolytics-dimension-repository_nwo | python/typeshed |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 31696383 |
| octolytics-dimension-repository_network_root_nwo | python/typeshed |
| 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 | 44c658b24abf00491fb7ae5f56d42c9f38cbeab2 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width