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

Partial type that is "initialised" via assignment is only temporarily narrowed by isinstance #18238

Open
tyralla opened this issue Dec 3, 2024 · 0 comments
Labels
bug mypy got something wrong topic-type-narrowing Conditional type narrowing / binder

Comments

@tyralla
Copy link
Collaborator

tyralla commented Dec 3, 2024

In the following example, the last revealed type could/should be Union[builtins.int, None]:

def f() -> bool: 
    return True

u: int | tuple[int]
x = None
if f():
    x = u
    if isinstance(x, tuple):
        x = x[0]
    reveal_type(x)  # note: "builtins.int"
reveal_type(x)  # note: Revealed type is "Union[builtins.int, Tuple[builtins.int], None]"

See this comment for background information.

@tyralla tyralla added bug mypy got something wrong topic-type-narrowing Conditional type narrowing / binder labels Dec 3, 2024
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

No branches or pull requests

1 participant