-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statement
Description
Bug Report
The conditions for reproducing this bug:
- You have at least one function that is decorated with a decorator which Mypy lacks typestubs for.
- Decorated classes do not appear to trigger this bug.
- You reference this function from at least one
case
inside an exhaustivematch
statement. - The function definition appears after the
match
statement.- Moving the decorated function above the
match
statement is an effective workaround for this bug.
- Moving the decorated function above the
- You have enabled the
exhaustive-match
error code.
To Reproduce
Please reference this playground link: https://mypy-play.net/?mypy=latest&python=3.12&flags=ignore-missing-imports&enable-error-code=exhaustive-match&gist=a5cdad420b204b5b0bb2ce278a6513ab
import unknown_module
import enum
class MyEnum(enum.Enum):
THIS = enum.auto()
THAT = enum.auto()
def get_fn(e: MyEnum):
match e:
case MyEnum.THIS:
fn = _this
case MyEnum.THAT:
fn = _that
# Using mypy with `exhaustive-match`, we can ignore the `possibly-undefined`
return fn # type: ignore[possibly-undefined]
@unknown_module.decorate
def _this():
pass
@unknown_module.decorate
def _that():
pass
Expected Behavior
No exhaustive-match
error should be emitted, because the match
expression is exhaustive.
Actual Behavior
The following error is emitted:
Match statement has unhandled case for values of type "Any | Any" [exhaustive-match]
The confusion created by this error may be compounded if you have ignore-missing-imports
on, because the import-not-found
error, which hints at the root cause, would be suppressed.
Your Environment
- Mypy version used: 1.17.1
- Mypy command-line flags: (none)
- Mypy configuration options from
mypy.ini
(and other config files):
[mypy]
ignore_missing_imports = true
enable_error_code = exhaustive-match
- Python version used: 3.11.11
ramya-rav, synspratama and sterliakov
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statement