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
from typing import Union, Dict
x = {} # type: Dict[str, Union[int, str]]
n = ''
if isinstance(x[n], int):
reveal_type(x[n]) # E: Revealed type is 'Union[builtins.int, builtins.str]'
Perhaps mypy should infer type int for x[n] (i.e. put x[n] into the conditional type binder).
The example can be refactored to type check pretty easily:
...
t = x[n]
if isinstance(t, int):
...
A slightly more interesting example that is a bit harder to get to type check:
...
if n in x and isinstance(x[n], int):
...
This was originally reported by @davire on gitter.
The text was updated successfully, but these errors were encountered:
Consider this fragment:
Perhaps mypy should infer type
int
forx[n]
(i.e. putx[n]
into the conditional type binder).The example can be refactored to type check pretty easily:
A slightly more interesting example that is a bit harder to get to type check:
This was originally reported by @davire on gitter.
The text was updated successfully, but these errors were encountered: