-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
bugmypy got something wrongmypy got something wrongtopic-enumtopic-match-statementPython 3.10's match statementPython 3.10's match statementtopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly
Description
Bug Report
When using structural pattern matching to compare an int
vs an http.HTTPStatus
instance (and vice versa), mypy gets the type wrong or thinks the code is unreachable.
To Reproduce
from http import HTTPStatus
from typing import reveal_type
code = 200
match code:
case HTTPStatus():
pass
case HTTPStatus.OK:
reveal_type(code)
case _:
pass
status = HTTPStatus.OK
match status:
case 200:
reveal_type(status)
case _:
pass
Expected Behavior
The revealed types should be int
and Literal[HTTPStatus.OK]
.
Actual Behavior
main.py:10: note: Revealed type is "Literal[http.HTTPStatus.OK]"
main.py:19: note: Revealed type is "Never"
Success: no issues found in 1 source file
Your Environment
- Mypy version used: 1.15.0
- Mypy command-line flags: --strict --warn-unreachable
- Python version used: 3.13
sk-
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-enumtopic-match-statementPython 3.10's match statementPython 3.10's match statementtopic-runtime-semanticsmypy doesn't model runtime semantics correctlymypy doesn't model runtime semantics correctly