Title: contextlib.contextmanager allows `Iterator[T]` -- should probably be `Generator[T, None, None]`? · Issue #2772 · python/typeshed · GitHub
Open Graph Title: contextlib.contextmanager allows `Iterator[T]` -- should probably be `Generator[T, None, None]`? · Issue #2772 · python/typeshed
X Title: contextlib.contextmanager allows `Iterator[T]` -- should probably be `Generator[T, None, None]`? · Issue #2772 · python/typeshed
Description: For instance, this script passes mypy: import contextlib from typing import Iterator @contextlib.contextmanager def f() -> Iterator[int]: return iter([1]) with f(): pass with f(): raise TypeError('wat') but fails at runtime (and not in t...
Open Graph Description: For instance, this script passes mypy: import contextlib from typing import Iterator @contextlib.contextmanager def f() -> Iterator[int]: return iter([1]) with f(): pass with f(): raise TypeError('...
X Description: For instance, this script passes mypy: import contextlib from typing import Iterator @contextlib.contextmanager def f() -> Iterator[int]: return iter([1]) with f(): pass with f(): raise TypeErro...
Opengraph URL: https://github.com/python/typeshed/issues/2772
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"contextlib.contextmanager allows `Iterator[T]` -- should probably be `Generator[T, None, None]`?","articleBody":"For instance, this script passes mypy:\r\n\r\n```python\r\nimport contextlib\r\nfrom typing import Iterator\r\n\r\n@contextlib.contextmanager\r\ndef f() -> Iterator[int]:\r\n return iter([1])\r\n\r\n\r\nwith f():\r\n pass\r\n\r\n\r\nwith f():\r\n raise TypeError('wat')\r\n```\r\n\r\nbut fails at runtime (and not in the expected way):\r\n\r\n```console\r\n$ python t.py \r\nTraceback (most recent call last):\r\n File \"t.py\", line 14, in \u003cmodule>\r\n raise TypeError('wat')\r\nTypeError: wat\r\n\r\nDuring handling of the above exception, another exception occurred:\r\n\r\nTraceback (most recent call last):\r\n File \"t.py\", line 14, in \u003cmodule>\r\n raise TypeError('wat')\r\n File \"/usr/lib/python3.6/contextlib.py\", line 99, in __exit__\r\n self.gen.throw(type, value, traceback)\r\nAttributeError: 'list_iterator' object has no attribute 'throw'\r\n```","author":{"url":"https://github.com/asottile","@type":"Person","name":"asottile"},"datePublished":"2019-01-30T00:06:39Z","url":"https://github.com/python/typeshed/issues/2772"}
| 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:09be3d50-30d7-7a4b-34dd-495eceaf80a3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D9D8:3F7946:1F144E3:2A3C087:6B001A1E |
| html-safe-nonce | a0f9b140ef4add67f5864d2cbf2a1bbccdc8f3c24ee79a62c35d2a8a27249371 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEOUQ4OjNGNzk0NjoxRjE0NEUzOjJBM0MwODc6NkIwMDFBMUUiLCJ2aXNpdG9yX2lkIjoiNTg0Nzc4ODExMzUwMTM2MjcxOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | f6c7d0c053f9c64fccbbc67d0ec01a4461373e0a66375dea1949b092d8cb1d6c |
| hovercard-subject-tag | issue:404542703 |
| 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/2772/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a20cef35efb18f66e8192e709b7df7085ca57f4561adfcddd266a16045f68f46/python/typeshed/issues/2772 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a20cef35efb18f66e8192e709b7df7085ca57f4561adfcddd266a16045f68f46/python/typeshed/issues/2772 |
| og:image:alt | For instance, this script passes mypy: import contextlib from typing import Iterator @contextlib.contextmanager def f() -> Iterator[int]: return iter([1]) with f(): pass with f(): raise TypeError('... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | asottile |
| hostname | github.com |
| expected-hostname | github.com |
| None | a2dd2291b1b13cc9c06f27ec92fa3dbaf34116fc24c9347b8539db61884c59f4 |
| 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 | 70121d4e855ee0bb7b75cf15d061d91f8863c0f8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width