-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Open
Labels
bugmypy got something wrongmypy got something wrongtopic-dataclassestopic-match-statementPython 3.10's match statementPython 3.10's match statement
Description
Bug Report
Pattern matching on a dataclass with a field of different type than required by the dataclass fails with Cannot determine type of ... for Python 3.13 and higher
To Reproduce
3.12 working gist: https://mypy-play.net/?mypy=latest&python=3.12&gist=f2947a04a9a86defefd16e54c0133c84
3.13 failing gist: https://mypy-play.net/?mypy=latest&python=3.13&gist=f2947a04a9a86defefd16e54c0133c84
from dataclasses import dataclass
@dataclass
class A:
pass
@dataclass
class B:
pass
@dataclass
class C:
sth: A
def func(c: C, b: B):
match c:
case C(B() as obj) if obj == b:
print("matched")Expected Behavior
I believe it should resolve the type same as for <= 3.12.
Actual Behavior
For Python >= 3.13 inferring obj type fails with:
repro.py:17: error: Cannot determine type of "obj" [has-type]
Your Environment
- Mypy version used:
1.19.1 - Mypy command-line flags:
mypy repro.py - Mypy configuration options from
mypy.ini(and other config files): no additional config - Python version used:
3.13.5
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugmypy got something wrongmypy got something wrongtopic-dataclassestopic-match-statementPython 3.10's match statementPython 3.10's match statement