-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
featuretopic-match-statementPython 3.10's match statementPython 3.10's match statementtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder
Description
The bug
It seems that doing a "type checking" with the object UI in pattern matching seems to not work properly.
Attribute match is not considered.
Code
class Test:
def __init__(self, a: int | str):
self.a: int | str = a
test = Test(5)
match test:
case Test(a = int()):
print(test.a + 3)
case Test(a = str()):
print(test.a + "3")Expected behavior
By doing a match with Test(a = int()), python will check test is of type Test AND test.a is of type int.
But mypy "only assert" that test if of type Test. It keep the type int | str for test.a.
Reproduce :
On mypy-playground :
https://mypy-play.net/?mypy=latest&python=3.11&gist=6f05124abd1ef68032d59651a7d5c6c3
tjkuson
Metadata
Metadata
Assignees
Labels
featuretopic-match-statementPython 3.10's match statementPython 3.10's match statementtopic-type-narrowingConditional type narrowing / binderConditional type narrowing / binder