Title: Reachable code marked as unreachable in generic class with None type · Issue #8871 · python/mypy · GitHub
Open Graph Title: Reachable code marked as unreachable in generic class with None type · Issue #8871 · python/mypy
X Title: Reachable code marked as unreachable in generic class with None type · Issue #8871 · python/mypy
Description: T = TypeVar("T") class A(Generic[T]): def __init__(self, a: T) -> None: self.a = a def __str__(self) -> str: if self.a is None: return "Foo" return "Bar" Running mypy on this code with warn_unreachable = True results in error that return...
Open Graph Description: T = TypeVar("T") class A(Generic[T]): def __init__(self, a: T) -> None: self.a = a def __str__(self) -> str: if self.a is None: return "Foo" return "Bar" Running mypy on this code with warn_unreach...
X Description: T = TypeVar("T") class A(Generic[T]): def __init__(self, a: T) -> None: self.a = a def __str__(self) -> str: if self.a is None: return "Foo" return "Bar" Running...
Opengraph URL: https://github.com/python/mypy/issues/8871
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Reachable code marked as unreachable in generic class with None type","articleBody":"```\r\nT = TypeVar(\"T\")\r\n\r\n\r\nclass A(Generic[T]):\r\n def __init__(self, a: T) -> None:\r\n self.a = a\r\n\r\n def __str__(self) -> str:\r\n if self.a is None:\r\n return \"Foo\"\r\n return \"Bar\"\r\n```\r\nRunning mypy on this code with `warn_unreachable = True` results in error that `return \"Foo\"` is unreachable. I wasn't able to find anywhere that NoneType is not correct type for the TypeVar and extending this class with NoneType doesn't result in error as well.\r\n\r\n```\r\nclass B(A[None]): ...\r\n```\r\n","author":{"url":"https://github.com/badochov","@type":"Person","name":"badochov"},"datePublished":"2020-05-22T09:05:02Z","url":"https://github.com/python/mypy/issues/8871"}
| 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:85f9df53-9b8b-3f5d-2985-8ec2c91143ea |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 94AE:1BAE29:7F6B0:B4A42:6B004EC6 |
| html-safe-nonce | f2e621375d2e8f242005ed70ab0e8dac52ac653c10a510c4e4d320b4bc0f70ae |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5NEFFOjFCQUUyOTo3RjZCMDpCNEE0Mjo2QjAwNEVDNiIsInZpc2l0b3JfaWQiOiI1MzY5NDIxNjMwMDc2NTU2MjIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | e565615a3796ce993a9ff5b5bccfa25d2af206a8ff28d4013f13240620f68119 |
| hovercard-subject-tag | issue:623066277 |
| 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/8871/issue_layout |
| twitter:image | https://opengraph.githubassets.com/06608fd0eda6785a06bede702c63f3b5ee57396806a3c295641a5892b940b74d/python/mypy/issues/8871 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/06608fd0eda6785a06bede702c63f3b5ee57396806a3c295641a5892b940b74d/python/mypy/issues/8871 |
| og:image:alt | T = TypeVar("T") class A(Generic[T]): def __init__(self, a: T) -> None: self.a = a def __str__(self) -> str: if self.a is None: return "Foo" return "Bar" Running mypy on this code with warn_unreach... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | badochov |
| hostname | github.com |
| expected-hostname | github.com |
| None | f420f4996e6b1ff1ccd6d7683f8134f4b5f0f8a50124c210dbfe7490e5644abb |
| 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 | 26e00df917aba0f128135dc073ea0c5e33a70d40 |
| ui-target | canary-2 |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width