-
-
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
The following code fails to type check with error: "str" has no attribute "bit_length"
on the match statement, but not on the print statement:
def redefinition(a: str):
a = int(a)
print(a.bit_length())
match a.bit_length():
case _:
...
The same function without the match statement passes type checking, see https://mypy-play.net/?mypy=master&python=3.11&flags=allow-redefinition&gist=ab4ccfc9e1db52c94b98c8b4d790e7d1
The opposite case does pass type checking while it shouldn't:
def redefinition_other_way(a: int):
a = str(a)
match a.bit_length():
case _:
...
It seems like match statements do not consider redefinitions properly.
Your Environment
- Mypy version used: ed3a6c1
- Mypy command-line flags:
--allow-redefinition
- Python version used:
Python 3.10.9
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-match-statementPython 3.10's match statementPython 3.10's match statement