Mypy 1.7.0 makes two incorrect inferences about dataclass descriptor-based fields #16538
Labels
bug
mypy got something wrong
topic-dataclasses
topic-descriptors
Properties, class vs. instance attributes
Bug Report
When a dataclass field uses a descriptor, Mypy makes two incorrect inferences:
dataclasses._get_field
, asdefault = getattr(cls, a_name, MISSING)
.InitVar
, mypy incorrectly assumes the attribute does not exist on the class.To Reproduce
https://mypy-play.net/?mypy=latest&python=3.11&gist=8a47d8538f2fc798a8564d30dae6434e
Expected Behavior
No error, matching runtime behaviour and the internal validations of the
@dataclass
decorator.Actual Behavior
Two incorrect errors:
Your Environment
Related: #13856 describes another dataclass descriptor bug, fixed in mypy 1.2.
The text was updated successfully, but these errors were encountered: