Title: Wrong type inferred when "not in" narrowing Any · Issue #17841 · python/mypy · GitHub
Open Graph Title: Wrong type inferred when "not in" narrowing Any · Issue #17841 · python/mypy
X Title: Wrong type inferred when "not in" narrowing Any · Issue #17841 · python/mypy
Description: The revealed type here is str | None, which doesn't make sense: from typing import Any def f(x: Any) -> None: if x is not None and x not in ["x"]: return reveal_type(x) # "str | None" The behavior was changed in ed0cd4a. The inferred typ...
Open Graph Description: The revealed type here is str | None, which doesn't make sense: from typing import Any def f(x: Any) -> None: if x is not None and x not in ["x"]: return reveal_type(x) # "str | None" The behavior ...
X Description: The revealed type here is str | None, which doesn't make sense: from typing import Any def f(x: Any) -> None: if x is not None and x not in ["x"]: return reveal_type(x) # "str...
Opengraph URL: https://github.com/python/mypy/issues/17841
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Wrong type inferred when \"not in\" narrowing Any ","articleBody":"The revealed type here is `str | None`, which doesn't make sense:\r\n```py\r\nfrom typing import Any\r\n\r\ndef f(x: Any) -\u003e None:\r\n if x is not None and x not in [\"x\"]:\r\n return\r\n reveal_type(x) # \"str | None\"\r\n```\r\nThe behavior was changed in ed0cd4acba02ed19b1cf18ac0ac416dc251d7714. The inferred type before this commit was `Any`, which seems reasonable.","author":{"url":"https://github.com/JukkaL","@type":"Person","name":"JukkaL"},"datePublished":"2024-09-27T10:03:38.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/17841/mypy/issues/17841"}
| 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:b1a8baa1-42dd-08b3-8d88-0ab92ff4bc20 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 8D7E:8C7D0:2568946:359C709:6A58F8CA |
| html-safe-nonce | c8a99675162eb71779c462f18ebb5a01449616accc227d90ec675b5647d1f145 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4RDdFOjhDN0QwOjI1Njg5NDY6MzU5QzcwOTo2QTU4RjhDQSIsInZpc2l0b3JfaWQiOiI3OTAyMjU5MTU5NDU0MjUxMjEwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | c75482c003697397d528eaf4e096807b8aeead5296dee13401f6545460fe5eb0 |
| hovercard-subject-tag | issue:2552528956 |
| 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/17841/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2f2fcc74bec597146cf579f2ad919f6fe7389dfb67edbca7936fd2bf28c4f1bc/python/mypy/issues/17841 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2f2fcc74bec597146cf579f2ad919f6fe7389dfb67edbca7936fd2bf28c4f1bc/python/mypy/issues/17841 |
| og:image:alt | The revealed type here is str | None, which doesn't make sense: from typing import Any def f(x: Any) -> None: if x is not None and x not in ["x"]: return reveal_type(x) # "str | None" The behavior ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | JukkaL |
| 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