You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Weird behaviour with TypeVar and conditional expression containing isinstance() #9195
I am using Python 3.8.3 and mypy 0.782. Depending on TypeVar definition I get following results:
$ grep "^T = TypeVar" snippet.py
T = TypeVar("T", N, Tuple[N, N])
$ mypy-3.8 snippet.py
snippet.py:12: error: "Tuple[N, N]" has no attribute "name"
Found 1 error in 1 file (checked 1 source file)
$ grep "^T = TypeVar" snippet.py
T = TypeVar("T", N, Tuple[N, ...])
$ mypy-3.8 snippet.py
Success: no issues found in 1 source file
This means the conditional expression containing isinstance() in function get_name_bad() does trigger error while normal if-block with isinstance() from get_name_good() doesnt. All of this is happening only with fixed-length tuple in TypeVar and not with variable length tuple.
I would expect there is no difference between Tuple[N, N] and Tuple[N, ...] when checking the type via isinstance() in conditional expression.
Activity
hauntsaninja commentedon Jul 24, 2020
Seems similar to #4134
Suppress errors for unreachable branches in conditional expressions (p…