diff --git a/codeforlife/serializers/base.py b/codeforlife/serializers/base.py index a49d0a2c..5c8fbf0c 100644 --- a/codeforlife/serializers/base.py +++ b/codeforlife/serializers/base.py @@ -11,7 +11,13 @@ from rest_framework.serializers import BaseSerializer as _BaseSerializer from ..request import Request -from ..user.models import AnyUser as RequestUser + +if t.TYPE_CHECKING: + from ..user.models import User + + RequestUser = t.TypeVar("RequestUser", bound=User) +else: + RequestUser = t.TypeVar("RequestUser") # pylint: disable-next=abstract-method diff --git a/codeforlife/serializers/model.py b/codeforlife/serializers/model.py index 1300483c..ad99c180 100644 --- a/codeforlife/serializers/model.py +++ b/codeforlife/serializers/model.py @@ -13,9 +13,15 @@ from rest_framework.serializers import ValidationError as _ValidationError from ..types import DataDict, OrderedDataDict -from ..user.models import AnyUser as RequestUser from .base import BaseSerializer +if t.TYPE_CHECKING: + from ..user.models import User + + RequestUser = t.TypeVar("RequestUser", bound=User) +else: + RequestUser = t.TypeVar("RequestUser") + AnyModel = t.TypeVar("AnyModel", bound=Model) diff --git a/codeforlife/tests/model_serializer.py b/codeforlife/tests/model_serializer.py index 8c6cc7bf..232e897b 100644 --- a/codeforlife/tests/model_serializer.py +++ b/codeforlife/tests/model_serializer.py @@ -15,10 +15,17 @@ from ..serializers import ModelListSerializer, ModelSerializer from ..types import DataDict -from ..user.models import AnyUser as RequestUser from .api_request_factory import APIRequestFactory from .test import TestCase +if t.TYPE_CHECKING: + from ..user.models import User + + RequestUser = t.TypeVar("RequestUser", bound=User) +else: + RequestUser = t.TypeVar("RequestUser") + + AnyModel = t.TypeVar("AnyModel", bound=Model) diff --git a/codeforlife/tests/model_view_set.py b/codeforlife/tests/model_view_set.py index 855bbf02..bd944a9f 100644 --- a/codeforlife/tests/model_view_set.py +++ b/codeforlife/tests/model_view_set.py @@ -19,10 +19,16 @@ from ..permissions import Permission from ..serializers import BaseSerializer from ..types import DataDict, JsonDict, KwArgs -from ..user.models import AnyUser as RequestUser from ..views import ModelViewSet from .api import APIClient, APITestCase +if t.TYPE_CHECKING: + from ..user.models import User + + RequestUser = t.TypeVar("RequestUser", bound=User) +else: + RequestUser = t.TypeVar("RequestUser") + AnyModel = t.TypeVar("AnyModel", bound=Model) # pylint: disable=no-member,too-many-arguments diff --git a/codeforlife/views/model.py b/codeforlife/views/model.py index 14ed52fa..71516997 100644 --- a/codeforlife/views/model.py +++ b/codeforlife/views/model.py @@ -16,7 +16,6 @@ from ..permissions import Permission from ..request import Request from ..types import KwArgs -from ..user.models import AnyUser as RequestUser from .api import APIView from .decorators import action @@ -24,6 +23,9 @@ if t.TYPE_CHECKING: # pragma: no cover from ..serializers import ModelListSerializer, ModelSerializer + from ..user.models import User + + RequestUser = t.TypeVar("RequestUser", bound=User) # NOTE: This raises an error during runtime. # pylint: disable-next=too-few-public-methods @@ -31,6 +33,8 @@ class _ModelViewSet(DrfModelViewSet[AnyModel], t.Generic[AnyModel]): pass else: + RequestUser = t.TypeVar("RequestUser") + # pylint: disable-next=too-many-ancestors class _ModelViewSet(DrfModelViewSet, t.Generic[AnyModel]): pass