Skip to content

Commit

Permalink
session param
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Nov 5, 2024
1 parent 9c0463d commit 623f995
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
9 changes: 5 additions & 4 deletions codeforlife/request/drf.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typing as t

from django.contrib.auth.models import AbstractBaseUser, AnonymousUser
from django.contrib.sessions.backends.db import SessionStore as DBStore
from rest_framework.request import Request as _Request

from ..types import JsonDict, JsonList
Expand All @@ -21,12 +22,14 @@
else:
AnyUser = t.TypeVar("AnyUser")

AnyDBStore = t.TypeVar("AnyDBStore", bound=DBStore)
AnyAbstractBaseUser = t.TypeVar("AnyAbstractBaseUser", bound=AbstractBaseUser)


# pylint: disable-next=missing-class-docstring,abstract-method
class BaseRequest(_Request, t.Generic[AnyAbstractBaseUser]):
class BaseRequest(_Request, t.Generic[AnyDBStore, AnyAbstractBaseUser]):
data: t.Any
session: AnyDBStore
user: t.Union[AnyAbstractBaseUser, AnonymousUser]

@property
Expand Down Expand Up @@ -55,9 +58,7 @@ def json_list(self):


# pylint: disable-next=missing-class-docstring,abstract-method
class Request(BaseRequest[AnyUser], t.Generic[AnyUser]):
session: "SessionStore"

class Request(BaseRequest["SessionStore", AnyUser], t.Generic[AnyUser]):
def __init__(self, user_class: t.Type[AnyUser], *args, **kwargs):
super().__init__(*args, **kwargs)
self.user_class = user_class
Expand Down
9 changes: 6 additions & 3 deletions codeforlife/request/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typing as t

from django.contrib.auth.models import AbstractBaseUser, AnonymousUser
from django.contrib.sessions.backends.db import SessionStore as DBStore
from django.http import HttpRequest as _HttpRequest

# pylint: disable-next=duplicate-code
Expand All @@ -19,14 +20,16 @@
else:
AnyUser = t.TypeVar("AnyUser")

AnyDBStore = t.TypeVar("AnyDBStore", bound=DBStore)
AnyAbstractBaseUser = t.TypeVar("AnyAbstractBaseUser", bound=AbstractBaseUser)


# pylint: disable-next=missing-class-docstring
class BaseHttpRequest(_HttpRequest, t.Generic[AnyAbstractBaseUser]):
class BaseHttpRequest(_HttpRequest, t.Generic[AnyDBStore, AnyAbstractBaseUser]):
session: AnyDBStore
user: t.Union[AnyAbstractBaseUser, AnonymousUser]


# pylint: disable-next=missing-class-docstring
class HttpRequest(BaseHttpRequest[AnyUser], t.Generic[AnyUser]):
session: "SessionStore"
class HttpRequest(BaseHttpRequest["SessionStore", AnyUser], t.Generic[AnyUser]):
pass
9 changes: 6 additions & 3 deletions codeforlife/request/wsgi.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import typing as t

from django.contrib.auth.models import AbstractBaseUser, AnonymousUser
from django.contrib.sessions.backends.db import SessionStore as DBStore
from django.core.handlers.wsgi import WSGIRequest as _WSGIRequest

# pylint: disable-next=duplicate-code
Expand All @@ -19,14 +20,16 @@
else:
AnyUser = t.TypeVar("AnyUser")

AnyDBStore = t.TypeVar("AnyDBStore", bound=DBStore)
AnyAbstractBaseUser = t.TypeVar("AnyAbstractBaseUser", bound=AbstractBaseUser)


# pylint: disable-next=missing-class-docstring
class BaseWSGIRequest(_WSGIRequest, t.Generic[AnyAbstractBaseUser]):
class BaseWSGIRequest(_WSGIRequest, t.Generic[AnyDBStore, AnyAbstractBaseUser]):
session: AnyDBStore
user: t.Union[AnyAbstractBaseUser, AnonymousUser]


# pylint: disable-next=missing-class-docstring
class WSGIRequest(BaseWSGIRequest[AnyUser], t.Generic[AnyUser]):
session: "SessionStore"
class WSGIRequest(BaseWSGIRequest["SessionStore", AnyUser], t.Generic[AnyUser]):
pass

0 comments on commit 623f995

Please sign in to comment.