For the partially defined check (--enable-error-code partially-defined), mypy generates a false-positive in the following case:
deff1(x: int|str) ->int:
ifisinstance(x, int):
y=1elifisinstance(x, str): y=2returny# error: Name "y" may be undefined
The same applies to match statements:
deff(x: int|str) ->int:
matchx: caseint():
y=1casestr():
y=2returny# error: Name "y" may be undefined
It's likely that mypy already detects this somewhere, since it doesn't complain about the missing return:
deff3(x: int|str) ->int:
ifisinstance(x, int):
return1elifisinstance(x, str): return2
For the partially defined check (
--enable-error-code partially-defined), mypy generates a false-positive in the following case:The same applies to
matchstatements:It's likely that mypy already detects this somewhere, since it doesn't complain about the missing return: