oxan / djangorestframework-dataclasses

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

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

Closed intgr closed 1 year ago

intgr commented 1 year 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 1 year 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 1 year ago

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

oxan commented 1 year ago

I can commit a fix tomorrow.