Title: Mandatory Iterator with "yield" · Issue #633 · python/mypy · GitHub
Open Graph Title: Mandatory Iterator with "yield" · Issue #633 · python/mypy
X Title: Mandatory Iterator with "yield" · Issue #633 · python/mypy
Description: Is it intended that the use of yield mandates the return type Iterator? For example, if I want the squares of numbers: def get_squares(n: int) -> Iterable[int]: return [i**2 for i in range(n)] I cannot reimplement it as an iterator: def ...
Open Graph Description: Is it intended that the use of yield mandates the return type Iterator? For example, if I want the squares of numbers: def get_squares(n: int) -> Iterable[int]: return [i**2 for i in range(n)] I ca...
X Description: Is it intended that the use of yield mandates the return type Iterator? For example, if I want the squares of numbers: def get_squares(n: int) -> Iterable[int]: return [i**2 for i in range(n)] I...
Opengraph URL: https://github.com/python/mypy/issues/633
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Mandatory Iterator with \"yield\"","articleBody":"Is it intended that the use of `yield` mandates the return type `Iterator`?\nFor example, if I want the squares of numbers:\n\n```\ndef get_squares(n: int) -> Iterable[int]:\n return [i**2 for i in range(n)]\n```\n\nI cannot reimplement it as an iterator:\n\n```\ndef get_squares(n: int) -> Iterable[int]:\n for i in range(n):\n yield i**2\n```\n\nwithout getting `Iterator function return type expected for \"yield\"` (even if `Iterator` actually is a subclass of `Iterable`).\n\nHowever, it works with `yield from`:\n\n```\ndef get_squares(n: int) -> Iterable[int]:\n yield from (i**2 for i in range(n))\n```\n\nWhat is the reasoning?\n","author":{"url":"https://github.com/fcolas","@type":"Person","name":"fcolas"},"datePublished":"2015-04-13T15:36:52Z","url":"https://github.com/python/mypy/issues/633"}
| 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:6d0efedb-eb30-20da-d7a7-655a2daed2f5 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 93FA:7A49C:821115:B38BD4:6B00A280 |
| html-safe-nonce | 11f290cb5907fa04e40a8171c1f38f2ae41bc94bcb94b2048b466538ef243e82 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5M0ZBOjdBNDlDOjgyMTExNTpCMzhCRDQ6NkIwMEEyODAiLCJ2aXNpdG9yX2lkIjoiMjIzOTcxODUwNjI2ODUwMDYwOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 059bd06c2b9c68afa621df738932c6934ebbdb0146920e653ddf4b970791cd2d |
| hovercard-subject-tag | issue:68128449 |
| 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/633/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7f13afed860c4ddd39308b55079f09ce69f75e67c7d1d84c3b9f4b60c9537fb9/python/mypy/issues/633 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7f13afed860c4ddd39308b55079f09ce69f75e67c7d1d84c3b9f4b60c9537fb9/python/mypy/issues/633 |
| og:image:alt | Is it intended that the use of yield mandates the return type Iterator? For example, if I want the squares of numbers: def get_squares(n: int) -> Iterable[int]: return [i**2 for i in range(n)] I ca... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fcolas |
| hostname | github.com |
| expected-hostname | github.com |
| None | 455b493e3402a3a3a06beac5d20bb7db3da060808b220aa48d6a7eca7c59863a |
| 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 | 2f575159976167242d488c0b062eb355c4e198b7 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width