Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong type inferred when "not in" narrowing Any #17841

Closed
JukkaL opened this issue Sep 27, 2024 · 0 comments · Fixed by #17865
Closed

Wrong type inferred when "not in" narrowing Any #17841

JukkaL opened this issue Sep 27, 2024 · 0 comments · Fixed by #17865
Labels
bug mypy got something wrong topic-type-narrowing Conditional type narrowing / binder

Comments

@JukkaL
Copy link
Collaborator

JukkaL commented Sep 27, 2024

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 type before this commit was Any, which seems reasonable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-type-narrowing Conditional type narrowing / binder
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant