Title: Walrus operator + type inference + generic class + some other conditions = mypy failure · Issue #9743 · python/mypy · GitHub
Open Graph Title: Walrus operator + type inference + generic class + some other conditions = mypy failure · Issue #9743 · python/mypy
X Title: Walrus operator + type inference + generic class + some other conditions = mypy failure · Issue #9743 · python/mypy
Description: Bug Report from typing import ( Generic, TypeVar, ) _MyType = TypeVar("_MyType", str, float) class MyGeneric(Generic[_MyType]): def __init__(self, attr: int) -> None: ls = [0] self.attr = attr # mypy says: error: Need type annotation for...
Open Graph Description: Bug Report from typing import ( Generic, TypeVar, ) _MyType = TypeVar("_MyType", str, float) class MyGeneric(Generic[_MyType]): def __init__(self, attr: int) -> None: ls = [0] self.attr = attr # my...
X Description: Bug Report from typing import ( Generic, TypeVar, ) _MyType = TypeVar("_MyType", str, float) class MyGeneric(Generic[_MyType]): def __init__(self, attr: int) -> None: ls = [0] self.att...
Opengraph URL: https://github.com/python/mypy/issues/9743
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Walrus operator + type inference + generic class + some other conditions = mypy failure","articleBody":"**Bug Report**\r\n```python\r\nfrom typing import (\r\n Generic,\r\n TypeVar,\r\n)\r\n_MyType = TypeVar(\"_MyType\", str, float) \r\n\r\nclass MyGeneric(Generic[_MyType]):\r\n def __init__(self, attr: int) -> None:\r\n ls = [0]\r\n self.attr = attr # mypy says: error: Need type annotation for 'attr'\r\n if (a := sum(ls)): # mypy says: error: Cannot determine type of 'ls'\r\n pass\r\n reveal_type(ls) # mypy says: note: Revealed type is 'builtins.list[builtins.int*]'\r\n```\r\n\r\nThe title of this bug report was a bit vague because I didn't know how to concisely describe the necessary set of conditions for this bug. Here are those conditions:\r\n\r\n1. `ls` is not manually annotated.\r\n2. The walrus operator is used.\r\n4. The block is inside a generic class.\r\n5. `_MyType` is a TypeVar that explicitly enumerates all the possible types (as opposed to being `bound=...` or just a free TypeVar)\r\n\r\n**Environment**\r\nmypy 0.800+dev.40fd841a005936d95e7c351435f1b7b7b4bdd43d\r\nNo mypy.ini config, no cmdline flags.\r\nPython 3.8.3","author":{"url":"https://github.com/dnaaun","@type":"Person","name":"dnaaun"},"datePublished":"2020-11-22T10:01:21Z","url":"https://github.com/python/mypy/issues/9743"}
| 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:54db0686-f4a8-4691-fbdd-bbc8e0fe8778 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D868:1BAA33:50F7D7:6963F8:6AFFC272 |
| html-safe-nonce | 620338e4fca97d06d9cb5880f22bcf0c31ba716f09fc0da32f10e76bb4bccd18 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEODY4OjFCQUEzMzo1MEY3RDc6Njk2M0Y4OjZBRkZDMjcyIiwidmlzaXRvcl9pZCI6IjMxOTcxMTMxNTgwMjgyMTQ4OTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 9db2e649cf630087d5573809407f69793720e1a2a3b526b4a20848b58ada51fe |
| hovercard-subject-tag | issue:748209116 |
| 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/9743/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f6fc4f575fa9180df28fe89aeedbdc9c777c345ef3e2d2b211a8c1ce2ae00d44/python/mypy/issues/9743 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f6fc4f575fa9180df28fe89aeedbdc9c777c345ef3e2d2b211a8c1ce2ae00d44/python/mypy/issues/9743 |
| og:image:alt | Bug Report from typing import ( Generic, TypeVar, ) _MyType = TypeVar("_MyType", str, float) class MyGeneric(Generic[_MyType]): def __init__(self, attr: int) -> None: ls = [0] self.attr = attr # my... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | dnaaun |
| hostname | github.com |
| expected-hostname | github.com |
| None | 1e805b832df235bb21305db712c3b6432920019dfc12cb25b9cb8d3b0c9403cf |
| 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 | 8fa4a54e6871c7908eda1c246ad5972982c0b59d |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width