oxan / djangorestframework-dataclasses

Dataclasses serializer for Django REST framework
BSD 3-Clause "New" or "Revised" License
431 stars 28 forks source link

Mypy error: Type argument "X" of "DataclassSerializer" must be a subtype of "Dataclass" #64

Closed intgr closed 2 years ago

intgr commented 2 years ago

When using code like:

@dataclass
class MyDataclass:
    blah: int

class MySerializer(DataclassSerializer[MyDataclass]):
    ...

mypy version 0.990 will display a warning like:

Type argument "MyDataclass" of "DataclassSerializer" must be a subtype of "Dataclass"

I am not yet sure whether this is a bug or intentional change, reported to mypy for clarification: https://github.com/python/mypy/issues/14029

oxan commented 2 years ago

Marking __dataclass_fields__ as a ClassVar in the protocol makes sense imo. It's unfortunate that older mypy doesn't accept that, though.

intgr commented 2 years ago

@oxan Are you fixing this or should I submit a PR?

oxan commented 2 years ago

I can commit a fix tomorrow.