Open
Description
For the partially defined check (--enable-error-code partially-defined
), mypy generates a false-positive in the following case:
def f1(x: int | str) -> int:
if isinstance(x, int):
y = 1
elif isinstance(x, str):
y = 2
return y # error: Name "y" may be undefined
The same applies to match
statements:
def f(x: int | str) -> int:
match x:
case int():
y = 1
case str():
y = 2
return y # error: Name "y" may be undefined
It's likely that mypy already detects this somewhere, since it doesn't complain about the missing return:
def f3(x: int | str) -> int:
if isinstance(x, int):
return 1
elif isinstance(x, str):
return 2