Title: Incorrect 'Implicit return in function which does not return' when using 'contextlib.contextmanager' · Issue #8401 · python/mypy · GitHub
Open Graph Title: Incorrect 'Implicit return in function which does not return' when using 'contextlib.contextmanager' · Issue #8401 · python/mypy
X Title: Incorrect 'Implicit return in function which does not return' when using 'contextlib.contextmanager' · Issue #8401 · python/mypy
Description: Consider the following snippet. import contextlib import sys from typing import Iterator, NoReturn def foo() -> NoReturn: with bar(): pass sys.exit(0) @contextlib.contextmanager def bar() -> Iterator[None]: yield None Running mypy produc...
Open Graph Description: Consider the following snippet. import contextlib import sys from typing import Iterator, NoReturn def foo() -> NoReturn: with bar(): pass sys.exit(0) @contextlib.contextmanager def bar() -> Iterat...
X Description: Consider the following snippet. import contextlib import sys from typing import Iterator, NoReturn def foo() -> NoReturn: with bar(): pass sys.exit(0) @contextlib.contextmanager def bar() -> ...
Opengraph URL: https://github.com/python/mypy/issues/8401
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Incorrect 'Implicit return in function which does not return' when using 'contextlib.contextmanager'","articleBody":"Consider the following snippet.\r\n\r\n```python\r\nimport contextlib\r\nimport sys\r\nfrom typing import Iterator, NoReturn\r\n\r\ndef foo() -> NoReturn:\r\n with bar():\r\n pass\r\n sys.exit(0)\r\n\r\n\r\n@contextlib.contextmanager\r\ndef bar() -> Iterator[None]:\r\n yield None\r\n```\r\n\r\nRunning mypy produces\r\n\r\n```python\r\nerror: Implicit return in function which does not return [misc]\r\n def foo() -> NoReturn:\r\n ^\r\n```\r\n\r\nHand-writing the context manager (as follows) does not produce the same error.\r\n\r\n```python\r\nclass Bar:\r\n def __enter__(self) -> None:\r\n return None\r\n\r\n def __exit__(self, *args: Any) -> None:\r\n pass\r\n```\r\n\r\nI think the error in the contextlib case is a false positive.\r\n\r\nmypy version `0.761` and `0.770+dev.a07dbd00638c35729e30dfc4ae441a8985183563` (current master)\r\nPython version `3.6.9`\r\nflags `--ignore-missing-imports --check-untyped-defs --disallow-untyped-defs --no-implicit-optional --warn-unused-ignores`\r\n\r\nMay be related to https://github.com/python/mypy/issues/8129.","author":{"url":"https://github.com/tomwatson1024","@type":"Person","name":"tomwatson1024"},"datePublished":"2020-02-14T11:44:42Z","url":"https://github.com/python/mypy/issues/8401"}
| 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:d43666b2-3500-d2c6-18f2-9df0f988c567 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D12:18020:4580C4:5CF444:6B002C4C |
| html-safe-nonce | cea0787368a84133d43cae9a5041d14bdaad1f9e81dad34d96f13c42ecf329b3 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDEyOjE4MDIwOjQ1ODBDNDo1Q0Y0NDQ6NkIwMDJDNEMiLCJ2aXNpdG9yX2lkIjoiODEzNTA5MjAxNjY0MDk2MTYxMiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 538231c69dc43c8948fa76e11fe12c57cd08e584a1096fc10f98b1c944bd9cc0 |
| hovercard-subject-tag | issue:565277454 |
| 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/8401/issue_layout |
| twitter:image | https://opengraph.githubassets.com/4e3e983c23185d7578a2bb5d82bcd2648b71a5f48e566a87a485b9628006f93d/python/mypy/issues/8401 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/4e3e983c23185d7578a2bb5d82bcd2648b71a5f48e566a87a485b9628006f93d/python/mypy/issues/8401 |
| og:image:alt | Consider the following snippet. import contextlib import sys from typing import Iterator, NoReturn def foo() -> NoReturn: with bar(): pass sys.exit(0) @contextlib.contextmanager def bar() -> Iterat... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | tomwatson1024 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width