From 623f9952eacaf0a6ccb1f9d6ae3954e488c529b4 Mon Sep 17 00:00:00 2001 From: SKairinos Date: Tue, 5 Nov 2024 16:38:17 +0000 Subject: [PATCH] session param --- codeforlife/request/drf.py | 9 +++++---- codeforlife/request/http.py | 9 ++++++--- codeforlife/request/wsgi.py | 9 ++++++--- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/codeforlife/request/drf.py b/codeforlife/request/drf.py index 4c30da0..7162e0f 100644 --- a/codeforlife/request/drf.py +++ b/codeforlife/request/drf.py @@ -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 @@ -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 @@ -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 diff --git a/codeforlife/request/http.py b/codeforlife/request/http.py index 70678f8..3595c37 100644 --- a/codeforlife/request/http.py +++ b/codeforlife/request/http.py @@ -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 @@ -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 diff --git a/codeforlife/request/wsgi.py b/codeforlife/request/wsgi.py index b9764c8..72b3ca6 100644 --- a/codeforlife/request/wsgi.py +++ b/codeforlife/request/wsgi.py @@ -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 @@ -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