Closed
Description
Bug Report
With mypy 0.990 the dataclass __dataclass_fields__
attribute is now a ClassVar, which mypy considers to be incompatible with an instance attribute. This causes results like:
error: Incompatible types in assignment (expression has type "MyDataclass", variable has type "Dataclass") [assignment]
note: Protocol member Dataclass.__dataclass_fields__ expected instance variable, got class variable
Was this change intentional, do all users of this trick have to change __dataclass_fields__: dict
to ClassVar[dict]
, or is this an unintended result?
To Reproduce
https://mypy-play.net/?mypy=master&python=3.10&gist=c3bb7ee9862a0890e905a35dc1fe8209
class Dataclass(Protocol):
__dataclass_fields__: dict
@dataclass
class MyDataclass:
blah: int
x: Dataclass = MyDataclass(blah=123)
# ^ error: Incompatible types in assignment (expression has type "MyDataclass", variable has type "Dataclass") [assignment]
# note: Protocol member Dataclass.__dataclass_fields__ expected instance variable, got class variable
Expected Behavior
I'm not sure to be honest whether the new behavior is correct or not, wanted to make sure.
Seems to be related to #13721, pinging @hauntsaninja.