Title: Type not narrowed correctly for `if X in collection` · Issue #3229 · python/mypy · GitHub
Open Graph Title: Type not narrowed correctly for `if X in collection` · Issue #3229 · python/mypy
X Title: Type not narrowed correctly for `if X in collection` · Issue #3229 · python/mypy
Description: def foobar(foo: Union[str, float]): if foo in ['fizz', 'buzz']: reveal_type(foo) else: pass The revealed type is Union[builtins.str, builtins.float] but should be builtins.str
Open Graph Description: def foobar(foo: Union[str, float]): if foo in ['fizz', 'buzz']: reveal_type(foo) else: pass The revealed type is Union[builtins.str, builtins.float] but should be builtins.str
X Description: def foobar(foo: Union[str, float]): if foo in ['fizz', 'buzz']: reveal_type(foo) else: pass The revealed type is Union[builtins.str, builtins.float] but should be builtins.str
Opengraph URL: https://github.com/python/mypy/issues/3229
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Type not narrowed correctly for `if X in collection`","articleBody":"```python\r\ndef foobar(foo: Union[str, float]):\r\n if foo in ['fizz', 'buzz']:\r\n reveal_type(foo)\r\n else:\r\n pass\r\n```\r\n\r\nThe revealed type is `Union[builtins.str, builtins.float]` but should be `builtins.str`","author":{"url":"https://github.com/frexvahi","@type":"Person","name":"frexvahi"},"datePublished":"2017-04-24T09:28:39.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":6},"url":"https://github.com/3229/mypy/issues/3229"}
| 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:34dcec80-32c8-a6f5-6c07-52c26b87790e |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | E042:1A55AD:1F4201C:2CC7A97:6A58F1AF |
| html-safe-nonce | b91406dac8edb0ab8a87e2b08a4b10bb4f581add35a1e0952b72cf45eafc8d64 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJFMDQyOjFBNTVBRDoxRjQyMDFDOjJDQzdBOTc6NkE1OEYxQUYiLCJ2aXNpdG9yX2lkIjoiOTE1NjY0OTk1MzYyMzg2MzcyOCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | c4b681c2d1cd4890a7017b7395543a0713b52c9375188fbe5bc3e63f2e08434e |
| hovercard-subject-tag | issue:223756413 |
| 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/3229/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cb6496f509595e9a5f8502ef6a33bff3bd20bed23ffdfa70ce9f3a268e7127e5/python/mypy/issues/3229 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cb6496f509595e9a5f8502ef6a33bff3bd20bed23ffdfa70ce9f3a268e7127e5/python/mypy/issues/3229 |
| og:image:alt | def foobar(foo: Union[str, float]): if foo in ['fizz', 'buzz']: reveal_type(foo) else: pass The revealed type is Union[builtins.str, builtins.float] but should be builtins.str |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | frexvahi |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5f2a0c7865178af3d91dd9f13b0cdfc3c73a2529c873d2780bb4c01271a57ec6 |
| 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 | 8aae7b8d6caacacf5c66eaeb2702d8dc88d85b4a |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width