From 4e89908f0a2d4525553372f26fb498d3e847fa41 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Thu, 10 Nov 2022 22:08:18 +0200 Subject: [PATCH] Fix compatibility with mypy 0.990 --- rest_framework_dataclasses/types.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/rest_framework_dataclasses/types.py b/rest_framework_dataclasses/types.py index 5150edb..7f604aa 100644 --- a/rest_framework_dataclasses/types.py +++ b/rest_framework_dataclasses/types.py @@ -1,6 +1,6 @@ # Some type definitions that can be useful. -from typing import Dict +from typing import Dict, ClassVar, Union try: # Python 3.8 and later @@ -9,6 +9,12 @@ from typing_extensions import Final, Literal, Protocol -# Note that this doesn't actually work yet (https://stackoverflow.com/a/55240861) -class Dataclass(Protocol): +# for mypy 0.990+ +class NewStyleDataclassProtocol(Protocol): + __dataclass_fields__: ClassVar[Dict] + +# for mypy <0.990 +class OldStyleDataclassProtocol(Protocol): __dataclass_fields__: Dict + +Dataclass = Union[OldStyleDataclassProtocol, NewStyleDataclassProtocol]