Skip to content

Detect exhaustiveness in partially-defined variable checks #13926

Description

@ilinum

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

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions