Title: False positive with --warn-unreachable when an instance variable is modified inside a for loop · Issue #13973 · python/mypy · GitHub
Open Graph Title: False positive with --warn-unreachable when an instance variable is modified inside a for loop · Issue #13973 · python/mypy
X Title: False positive with --warn-unreachable when an instance variable is modified inside a for loop · Issue #13973 · python/mypy
Description: Bug Report mypy mark as unreachable code that is perfectly reachable, perhaps because it interprets an instance variable typed as Optional to always be None. To Reproduce from typing import Optional # executed with --warn-unreachable cla...
Open Graph Description: Bug Report mypy mark as unreachable code that is perfectly reachable, perhaps because it interprets an instance variable typed as Optional to always be None. To Reproduce from typing import Optiona...
X Description: Bug Report mypy mark as unreachable code that is perfectly reachable, perhaps because it interprets an instance variable typed as Optional to always be None. To Reproduce from typing import Optiona...
Opengraph URL: https://github.com/python/mypy/issues/13973
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False positive with --warn-unreachable when an instance variable is modified inside a for loop","articleBody":"**Bug Report**\r\n\r\nmypy mark as unreachable code that is perfectly reachable, perhaps because it interprets an instance variable typed as Optional to always be None.\r\n\r\n**To Reproduce**\r\n\r\n```python\r\n\r\n\r\nfrom typing import Optional\r\n\r\n# executed with --warn-unreachable\r\n\r\nclass A:\r\n x: Optional[int]\r\n\r\n def execute(self) -\u003e None:\r\n self.x = None\r\n for i in range(3):\r\n if self.x is None:\r\n self.x = 10\r\n else:\r\n self.x = 20 # error: Statement is unreachable [unreachable]\r\n print(self.x)\r\n\r\n\r\na = A()\r\na.execute()\r\n```\r\n\r\n[Gist](https://gist.github.com/mypy-play/c4a0b051484c30474289868dd9ceb8e5)\r\n[Playground URL](https://mypy-play.net/?mypy=latest\u0026python=3.10\u0026flags=warn-unreachable\u0026gist=c4a0b051484c30474289868dd9ceb8e5)\r\n\r\n**Expected Behavior**\r\n\r\nNo errors.\r\n\r\n**Actual Behavior**\r\n\r\nShowing: `error: Statement is unreachable [unreachable]`\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.982\r\n- Mypy command-line flags: --warn-unreachable\r\n- Mypy configuration options from `mypy.ini` (and other config files):\r\n- Python version used: 3.10\r\n\r\n","author":{"url":"https://github.com/autosquash","@type":"Person","name":"autosquash"},"datePublished":"2022-10-31T13:02:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/13973/mypy/issues/13973"}
| 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:28a774f6-60d2-c30f-c564-84c846787bab |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | BE16:1580D8:A03C4E:D87FEC:6A5B8CE1 |
| html-safe-nonce | f706d2ee25714d9cc980cc980a1f5c2a4816e027f5435457666778b1c5962068 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCRTE2OjE1ODBEODpBMDNDNEU6RDg3RkVDOjZBNUI4Q0UxIiwidmlzaXRvcl9pZCI6IjE4Nzk5NzExOTgzMTU3NTc3NyIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 334978981639633d93e1e5f0fbd0c86c9d0f70db9b2188593f915a987a7c9b4d |
| hovercard-subject-tag | issue:1429811976 |
| 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/13973/issue_layout |
| twitter:image | https://opengraph.githubassets.com/0d78cde0e42ee059106567199669274c28e49f2c74080bc48531625274b5a0d1/python/mypy/issues/13973 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/0d78cde0e42ee059106567199669274c28e49f2c74080bc48531625274b5a0d1/python/mypy/issues/13973 |
| og:image:alt | Bug Report mypy mark as unreachable code that is perfectly reachable, perhaps because it interprets an instance variable typed as Optional to always be None. To Reproduce from typing import Optiona... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | autosquash |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| 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 | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width