Title: mypy thinks variable is None even if assigned non-None value inside loop · Issue #11900 · python/mypy · GitHub
Open Graph Title: mypy thinks variable is None even if assigned non-None value inside loop · Issue #11900 · python/mypy
X Title: mypy thinks variable is None even if assigned non-None value inside loop · Issue #11900 · python/mypy
Description: Bug Report To Reproduce def foo() -> None: user = None while True: if user is None: user = 123 else: print(1 + "lol") foo() Expected Behavior mypy error + runtime error Actual Behavior no mypy error Your Environment Mypy version used: 0.930
Open Graph Description: Bug Report To Reproduce def foo() -> None: user = None while True: if user is None: user = 123 else: print(1 + "lol") foo() Expected Behavior mypy error + runtime error Actual Behavior no mypy erro...
X Description: Bug Report To Reproduce def foo() -> None: user = None while True: if user is None: user = 123 else: print(1 + "lol") foo() Expected Behavior mypy error + runtime error Actual Behavior...
Opengraph URL: https://github.com/python/mypy/issues/11900
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"mypy thinks variable is None even if assigned non-None value inside loop","articleBody":"**Bug Report**\r\n\r\n**To Reproduce**\r\n\r\n```\r\ndef foo() -\u003e None:\r\n user = None\r\n\r\n while True:\r\n if user is None:\r\n user = 123\r\n else:\r\n print(1 + \"lol\")\r\n\r\nfoo()\r\n```\r\n\r\n**Expected Behavior**\r\n\r\nmypy error + runtime error\r\n\r\n**Actual Behavior**\r\n\r\nno mypy error\r\n\r\n**Your Environment**\r\n\r\n- Mypy version used: 0.930","author":{"url":"https://github.com/Akuli","@type":"Person","name":"Akuli"},"datePublished":"2022-01-04T22:40:53.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":3},"url":"https://github.com/11900/mypy/issues/11900"}
| 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:fc5db21a-613b-17b9-38fa-f17f972aab81 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C390:1912EF:675218:890EC8:6A5B76F9 |
| html-safe-nonce | 12b80eec961ad084aa54585f75ba8724e3f93eb596d37203adf22138705c7f28 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMzkwOjE5MTJFRjo2NzUyMTg6ODkwRUM4OjZBNUI3NkY5IiwidmlzaXRvcl9pZCI6Ijg4NTg3MDc0MjM3NjA0NDcyMjUiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 8b31bdac21ab7a4a3ae3b9627ae2b4978eddcb71d27694c8a02825c01a6cf0c2 |
| hovercard-subject-tag | issue:1093811289 |
| 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/11900/issue_layout |
| twitter:image | https://opengraph.githubassets.com/3ea218c73c1251e3d09cda53d15eab31ecc14dc8b4a39e3845cb48ad013326a0/python/mypy/issues/11900 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/3ea218c73c1251e3d09cda53d15eab31ecc14dc8b4a39e3845cb48ad013326a0/python/mypy/issues/11900 |
| og:image:alt | Bug Report To Reproduce def foo() -> None: user = None while True: if user is None: user = 123 else: print(1 + "lol") foo() Expected Behavior mypy error + runtime error Actual Behavior no mypy erro... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Akuli |
| 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