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
importtypingdeftest(lookup: typing.Dict[str, typing.List[str]], key: str) ->None:
vals=lookup.get(key, ())
# reveal_type(vals) - Revealed type is 'Union[builtins.list[builtins.str], Tuple[]]'iflen(vals) !=1:
return# reveal_type(vals) - Revealed type is 'Union[builtins.list[builtins.str], Tuple[]]'print(vals[0]) # false positive: Tuple index out of range
I expect this code to be accepted by the type-checker without errors.
If len(vals) == 1, the Tuple[] case is impossible. The revealed type should change to just builtins.list[builtins.str] after the condition.
Mypy 0.770 already manages this with a if not vals: return check; it should also use len(tuple) <relop> integer-literal conditions to filter out tuple types that don't match the expected length.
The text was updated successfully, but these errors were encountered:
I expect this code to be accepted by the type-checker without errors.
If
len(vals) == 1
, theTuple[]
case is impossible. The revealed type should change to justbuiltins.list[builtins.str]
after the condition.Mypy 0.770 already manages this with a
if not vals: return
check; it should also uselen(tuple) <relop> integer-literal
conditions to filter out tuple types that don't match the expected length.The text was updated successfully, but these errors were encountered: