Skip to content

Commit

Permalink
fix: imports
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Nov 5, 2024
1 parent 84f4895 commit e380049
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
8 changes: 7 additions & 1 deletion codeforlife/serializers/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion codeforlife/serializers/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
9 changes: 8 additions & 1 deletion codeforlife/tests/model_serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
8 changes: 7 additions & 1 deletion codeforlife/tests/model_view_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion codeforlife/views/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,25 @@
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

AnyModel = t.TypeVar("AnyModel", bound=Model)

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
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
Expand Down

0 comments on commit e380049

Please sign in to comment.