From 3c241c7775638c723a7c2f214fcce4e2af4c30e4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=9Fuayip=20=C3=BCz=C3=BClmez?= Date: Tue, 30 May 2023 00:11:08 +0300 Subject: [PATCH 1/3] Improve typing in `contrib.session.backends` --- django-stubs/contrib/sessions/backends/base.pyi | 12 ++++++++---- django-stubs/contrib/sessions/backends/db.pyi | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/django-stubs/contrib/sessions/backends/base.pyi b/django-stubs/contrib/sessions/backends/base.pyi index a42f2eb76..a355ab387 100644 --- a/django-stubs/contrib/sessions/backends/base.pyi +++ b/django-stubs/contrib/sessions/backends/base.pyi @@ -13,17 +13,19 @@ class SessionBase(dict[str, Any]): modified: bool serializer: Any def __init__(self, session_key: str | None = ...) -> None: ... + @property + def key_salt(self) -> str: ... def set_test_cookie(self) -> None: ... def test_cookie_worked(self) -> bool: ... def delete_test_cookie(self) -> None: ... def encode(self, session_dict: dict[str, Any]) -> str: ... def decode(self, session_data: bytes | str) -> dict[str, Any]: ... - def has_key(self, key: Any) -> Any: ... - def keys(self) -> Any: ... - def values(self) -> Any: ... - def items(self) -> Any: ... + def has_key(self, key: Any) -> bool: ... def clear(self) -> None: ... def is_empty(self) -> bool: ... + def _get_new_session_key(self) -> str: ... + def _get_or_create_session_key(self) -> str: ... + def _validate_session_key(self) -> bool: ... def _get_session_key(self) -> str | None: ... def _set_session_key(self, value: str | None) -> None: ... @property @@ -32,6 +34,8 @@ class SessionBase(dict[str, Any]): def _session_key(self) -> str | None: ... @_session_key.setter def _session_key(self, value: str | None) -> None: ... + def _get_session(self, no_load: bool = ...) -> dict[str, Any]: ... + def get_session_cookie_age(self) -> int: ... def get_expiry_age(self, **kwargs: Any) -> int: ... def get_expiry_date(self, **kwargs: Any) -> datetime: ... def set_expiry(self, value: datetime | int | None) -> None: ... diff --git a/django-stubs/contrib/sessions/backends/db.pyi b/django-stubs/contrib/sessions/backends/db.pyi index 7fb112a29..76578a853 100644 --- a/django-stubs/contrib/sessions/backends/db.pyi +++ b/django-stubs/contrib/sessions/backends/db.pyi @@ -1,12 +1,11 @@ from django.contrib.sessions.backends.base import SessionBase from django.contrib.sessions.base_session import AbstractBaseSession -from django.contrib.sessions.models import Session from django.db.models.base import Model class SessionStore(SessionBase): def __init__(self, session_key: str | None = ...) -> None: ... @classmethod - def get_model_class(cls) -> type[Session]: ... + def get_model_class(cls) -> type[AbstractBaseSession]: ... @property def model(self) -> type[AbstractBaseSession]: ... def create_model_instance(self, data: dict[str, Model]) -> AbstractBaseSession: ... From 2ea36d2b4bda690871a2c9f2b2824a1fd6e8a661 Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Fri, 2 Jun 2023 16:15:15 +0300 Subject: [PATCH 2/3] Remove new underscore methods per PR review --- django-stubs/contrib/sessions/backends/base.pyi | 4 ---- 1 file changed, 4 deletions(-) diff --git a/django-stubs/contrib/sessions/backends/base.pyi b/django-stubs/contrib/sessions/backends/base.pyi index a355ab387..661a9f792 100644 --- a/django-stubs/contrib/sessions/backends/base.pyi +++ b/django-stubs/contrib/sessions/backends/base.pyi @@ -23,9 +23,6 @@ class SessionBase(dict[str, Any]): def has_key(self, key: Any) -> bool: ... def clear(self) -> None: ... def is_empty(self) -> bool: ... - def _get_new_session_key(self) -> str: ... - def _get_or_create_session_key(self) -> str: ... - def _validate_session_key(self) -> bool: ... def _get_session_key(self) -> str | None: ... def _set_session_key(self, value: str | None) -> None: ... @property @@ -34,7 +31,6 @@ class SessionBase(dict[str, Any]): def _session_key(self) -> str | None: ... @_session_key.setter def _session_key(self, value: str | None) -> None: ... - def _get_session(self, no_load: bool = ...) -> dict[str, Any]: ... def get_session_cookie_age(self) -> int: ... def get_expiry_age(self, **kwargs: Any) -> int: ... def get_expiry_date(self, **kwargs: Any) -> datetime: ... From 35641ce374a273d2e0725c2b3e03ce697757cd9d Mon Sep 17 00:00:00 2001 From: Marti Raudsepp Date: Fri, 2 Jun 2023 16:34:50 +0300 Subject: [PATCH 3/3] Add back keys, values, items methods --- django-stubs/contrib/sessions/backends/base.pyi | 3 +++ 1 file changed, 3 insertions(+) diff --git a/django-stubs/contrib/sessions/backends/base.pyi b/django-stubs/contrib/sessions/backends/base.pyi index 661a9f792..90dabee0f 100644 --- a/django-stubs/contrib/sessions/backends/base.pyi +++ b/django-stubs/contrib/sessions/backends/base.pyi @@ -21,6 +21,9 @@ class SessionBase(dict[str, Any]): def encode(self, session_dict: dict[str, Any]) -> str: ... def decode(self, session_data: bytes | str) -> dict[str, Any]: ... def has_key(self, key: Any) -> bool: ... + def keys(self) -> Any: ... + def values(self) -> Any: ... + def items(self) -> Any: ... def clear(self) -> None: ... def is_empty(self) -> bool: ... def _get_session_key(self) -> str | None: ...