Closed
Description
After a guard with isinstance
, mypy should consider the variable to be of that type.
For example:
def f(x: A) -> None:
if isinstance(x, B) and x.value:
pass
class A:
pass
class B(A):
value = 0
Here, mypy reports that x
doesn't have a field value
. This can of course be solved with a cast, but that is annoying to type and clutters the code. At least in simple case, mypy could infer that x
is of type B
in the rhs of the and-statement and in the block following the if-statement.