Title: False negative involving null checks on optional types · Issue #5423 · python/mypy · GitHub
Open Graph Title: False negative involving null checks on optional types · Issue #5423 · python/mypy
X Title: False negative involving null checks on optional types · Issue #5423 · python/mypy
Description: Here is a minimal program demonstrating the problem: foo = None for _ in range(2): if foo is not None: print(1[2]) foo = 1 Expected behavior: error: Value of type "int" is not indexable Actual behavior: mypy accepts the program as valid,...
Open Graph Description: Here is a minimal program demonstrating the problem: foo = None for _ in range(2): if foo is not None: print(1[2]) foo = 1 Expected behavior: error: Value of type "int" is not indexable Actual beha...
X Description: Here is a minimal program demonstrating the problem: foo = None for _ in range(2): if foo is not None: print(1[2]) foo = 1 Expected behavior: error: Value of type "int" is not indexable A...
Opengraph URL: https://github.com/python/mypy/issues/5423
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"False negative involving null checks on optional types","articleBody":"Here is a minimal program demonstrating the problem:\r\n```\r\nfoo = None\r\nfor _ in range(2):\r\n if foo is not None:\r\n print(1[2])\r\n foo = 1\r\n\r\n```\r\nExpected behavior:\r\nerror: Value of type \"int\" is not indexable\r\n\r\nActual behavior:\r\nmypy accepts the program as valid, when run with the --strict flag\r\n\r\nThis issue seems to be a problem with how mypy handles reassignment to None type variables, and static evaluation of conditionals. After line 1, `foo` has the type None according to mypy. Thus, mypy determines that the condition on line 3 will never hold, and thus doesn't do type checking for the body of the if statement. On line 5, foo's type changes to `Optional[int]`. This, however, will only be reflected in code that follows line 5.","author":{"url":"https://github.com/person594","@type":"Person","name":"person594"},"datePublished":"2018-08-06T15:01:51.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/5423/mypy/issues/5423"}
| 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:30a7f94a-11ab-685f-2825-0f34cc08d472 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 99A2:12D89D:325A42:417757:6A5BF16A |
| html-safe-nonce | a9f5e596a6c1b055dbbce8c7873e057090b06a64bcb9b131282e7fdd3d5b5823 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5OUEyOjEyRDg5RDozMjVBNDI6NDE3NzU3OjZBNUJGMTZBIiwidmlzaXRvcl9pZCI6IjMwNDAxNDg5NzAyNDgyMjgyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | e057a3925afa1de11b9e2c7fd09b99a18ebc1be11a6a55574396f42a74d845f4 |
| hovercard-subject-tag | issue:347961366 |
| 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/5423/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f1c4a952519d0e86c24683edd2ca9e606d5c6e3a32002865722821df50c4feb6/python/mypy/issues/5423 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f1c4a952519d0e86c24683edd2ca9e606d5c6e3a32002865722821df50c4feb6/python/mypy/issues/5423 |
| og:image:alt | Here is a minimal program demonstrating the problem: foo = None for _ in range(2): if foo is not None: print(1[2]) foo = 1 Expected behavior: error: Value of type "int" is not indexable Actual beha... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | person594 |
| 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