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
When refining an element of type Union[Tuple, Sequence] with the isinstance(x, Sequence) in a conditional, the Tuple part of the type is wrongly discarded in the branch.
To Reproduce
fromtypingimportSequence, Tuple, Uniondeftest_func(x: Union[Tuple[int], Sequence[str]]) ->str:
ifisinstance(x, Sequence):
reveal_type(x) # Revealed type is "typing.Sequence[builtins.str]"returnx[0] # raises no errorreturn"a"# Statement is unreachable
Expected Behavior
The revealed type of x should be Union[Tuple[int], Sequence[str]] or something equivalent. The line return x[0] should be marked as an issue, because currently test_func((1,)) returns 1 so the functions shouldn't typecheck.
Actual Behavior
test.py:6:21: note: Revealed type is "typing.Sequence[builtins.str]"
test.py:8:5: error: Statement is unreachable [unreachable]
Found 1 error in 1 file (checked 1 source file)
Your Environment
Used a fresh virtual environment
Mypy version used: 0.971
Python version used: 3.8
The text was updated successfully, but these errors were encountered:
Bug Report
When refining an element of type
Union[Tuple, Sequence]
with theisinstance(x, Sequence)
in a conditional, theTuple
part of the type is wrongly discarded in the branch.To Reproduce
Expected Behavior
The revealed type of
x
should beUnion[Tuple[int], Sequence[str]]
or something equivalent. The linereturn x[0]
should be marked as an issue, because currentlytest_func((1,))
returns1
so the functions shouldn't typecheck.Actual Behavior
Your Environment
Used a fresh virtual environment
The text was updated successfully, but these errors were encountered: