Skip to content

generic with constraints fails to narrow when using conditional expression #13048

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

Closed
DetachHead opened this issue Jul 1, 2022 · 1 comment
Closed
Labels
bug mypy got something wrong

Comments

@DetachHead
Copy link
Contributor

DetachHead commented Jul 1, 2022

from typing import TypeVar

class A:
    a: int
class B:
    b: int

T = TypeVar("T", A, B)

def foo(t: T):
    t.b if isinstance(t, B) else t.a # error: "B" has no attribute "a"
    
    if isinstance(t, B):
        t.b # no error
    else:
        t.a

https://mypy-play.net/?mypy=0.961&python=3.10&gist=1646ac27c8249ac4752a973d9b2b54d4

@DetachHead DetachHead added the bug mypy got something wrong label Jul 1, 2022
@DetachHead
Copy link
Contributor Author

duplicate of #4134

@DetachHead DetachHead closed this as not planned Won't fix, can't repro, duplicate, stale Jul 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

1 participant