diff --git a/django-stubs/contrib/sessions/backends/base.pyi b/django-stubs/contrib/sessions/backends/base.pyi index 0898f7c08..e72ec1147 100644 --- a/django-stubs/contrib/sessions/backends/base.pyi +++ b/django-stubs/contrib/sessions/backends/base.pyi @@ -1,5 +1,9 @@ +from _collections_abc import dict_items, dict_keys, dict_values +from collections.abc import Iterable from datetime import datetime, timedelta -from typing import Any +from typing import Any, overload + +from _typeshed import SupportsKeysAndGetItem VALID_KEY_CHARS: Any @@ -13,17 +17,39 @@ class SessionBase(dict[str, Any]): modified: bool serializer: Any def __init__(self, session_key: str | None = None) -> None: ... + async def aset(self, key: str, value: Any) -> None: ... @property def key_salt(self) -> str: ... + @overload + async def aget(self, key: str) -> Any | None: ... + @overload + async def aget(self, key: str, default: Any) -> Any: ... + @overload + async def apop(self, key: str) -> Any: ... + @overload + async def apop(self, key: str, default: Any) -> Any: ... + async def asetdefault(self, key: str, value: Any) -> Any: ... def set_test_cookie(self) -> None: ... + async def aset_test_cookie(self) -> None: ... def test_cookie_worked(self) -> bool: ... + async def atest_cookie_worked(self) -> bool: ... def delete_test_cookie(self) -> None: ... + async def adelete_test_cookie(self) -> None: ... def encode(self, session_dict: dict[str, Any]) -> str: ... def decode(self, session_data: bytes | str) -> dict[str, Any]: ... + @overload # type: ignore[override] + def update(self, dict_: SupportsKeysAndGetItem[str, Any]) -> None: ... + @overload + def update(self, dict_: Iterable[tuple[str, Any]]) -> None: ... + @overload + async def aupdate(self, dict_: SupportsKeysAndGetItem[str, Any]) -> None: ... + @overload + async def aupdate(self, dict_: Iterable[tuple[str, Any]]) -> None: ... def has_key(self, key: Any) -> bool: ... - def keys(self) -> Any: ... - def values(self) -> Any: ... - def items(self) -> Any: ... + async def ahas_key(self, key: Any) -> bool: ... + async def akeys(self) -> dict_keys[str, Any]: ... + async def avalues(self) -> dict_values[str, Any]: ... + async def aitems(self) -> dict_items[str, Any]: ... def clear(self) -> None: ... def is_empty(self) -> bool: ... def _get_session_key(self) -> str | None: ... @@ -36,15 +62,28 @@ class SessionBase(dict[str, Any]): def _session_key(self, value: str | None) -> None: ... def get_session_cookie_age(self) -> int: ... def get_expiry_age(self, **kwargs: Any) -> int: ... + async def aget_expiry_age(self, **kwargs: Any) -> int: ... def get_expiry_date(self, **kwargs: Any) -> datetime: ... + async def aget_expiry_date(self, **kwargs: Any) -> datetime: ... def set_expiry(self, value: datetime | timedelta | int | None) -> None: ... + async def aset_expiry(self, value: datetime | timedelta | int | None) -> None: ... def get_expire_at_browser_close(self) -> bool: ... + async def aget_expire_at_browser_close(self) -> bool: ... def flush(self) -> None: ... + async def aflush(self) -> None: ... def cycle_key(self) -> None: ... + async def acycle_key(self) -> None: ... def exists(self, session_key: str) -> bool: ... + async def aexists(self, session_key: str) -> bool: ... def create(self) -> None: ... + async def acreate(self) -> None: ... def save(self, must_create: bool = False) -> None: ... + async def asave(self, must_create: bool = False) -> None: ... def delete(self, session_key: str | None = None) -> None: ... + async def adelete(self, session_key: str | None = None) -> None: ... def load(self) -> dict[str, Any]: ... + async def aload(self) -> dict[str, Any]: ... @classmethod def clear_expired(cls) -> None: ... + @classmethod + async def aclear_expired(cls) -> None: ... diff --git a/django-stubs/contrib/sessions/backends/cache.pyi b/django-stubs/contrib/sessions/backends/cache.pyi index 1ae59120c..c628c4673 100644 --- a/django-stubs/contrib/sessions/backends/cache.pyi +++ b/django-stubs/contrib/sessions/backends/cache.pyi @@ -9,3 +9,4 @@ class SessionStore(SessionBase): def __init__(self, session_key: str | None = None) -> None: ... @property def cache_key(self) -> str: ... + async def acache_key(self) -> str: ... diff --git a/django-stubs/contrib/sessions/backends/cached_db.pyi b/django-stubs/contrib/sessions/backends/cached_db.pyi index 07a871428..86d142922 100644 --- a/django-stubs/contrib/sessions/backends/cached_db.pyi +++ b/django-stubs/contrib/sessions/backends/cached_db.pyi @@ -1,11 +1,15 @@ +from logging import Logger from typing import Any from django.contrib.sessions.backends.db import SessionStore as DBStore KEY_PREFIX: str +logger: Logger + class SessionStore(DBStore): cache_key_prefix: Any def __init__(self, session_key: str | None = None) -> None: ... @property def cache_key(self) -> str: ... + async def acache_key(self) -> str: ... diff --git a/django-stubs/contrib/sessions/backends/db.pyi b/django-stubs/contrib/sessions/backends/db.pyi index 397ea32b6..d550ec0e7 100644 --- a/django-stubs/contrib/sessions/backends/db.pyi +++ b/django-stubs/contrib/sessions/backends/db.pyi @@ -11,3 +11,4 @@ class SessionStore(SessionBase): @cached_property def model(self) -> type[AbstractBaseSession]: ... def create_model_instance(self, data: dict[str, Any]) -> AbstractBaseSession: ... + async def acreate_model_instance(self, data: dict[str, Any]) -> AbstractBaseSession: ... diff --git a/django-stubs/contrib/sessions/backends/file.pyi b/django-stubs/contrib/sessions/backends/file.pyi index 0a5f89744..dad541026 100644 --- a/django-stubs/contrib/sessions/backends/file.pyi +++ b/django-stubs/contrib/sessions/backends/file.pyi @@ -4,4 +4,3 @@ class SessionStore(SessionBase): storage_path: str file_prefix: str def __init__(self, session_key: str | None = None) -> None: ... - def clean(self) -> None: ... diff --git a/django-stubs/contrib/sessions/backends/signed_cookies.pyi b/django-stubs/contrib/sessions/backends/signed_cookies.pyi index f82ead57f..fa8c99e4c 100644 --- a/django-stubs/contrib/sessions/backends/signed_cookies.pyi +++ b/django-stubs/contrib/sessions/backends/signed_cookies.pyi @@ -1,3 +1,4 @@ from django.contrib.sessions.backends.base import SessionBase -class SessionStore(SessionBase): ... +class SessionStore(SessionBase): + async def aexists(self, session_key: str | None = None) -> bool: ... diff --git a/scripts/stubtest/allowlist.txt b/scripts/stubtest/allowlist.txt index 2ac951136..c7cd29663 100644 --- a/scripts/stubtest/allowlist.txt +++ b/scripts/stubtest/allowlist.txt @@ -477,3 +477,7 @@ django.db.migrations.recorder.Migration@AnnotatedWith django.contrib.auth.backends.UserModel django.contrib.auth.forms.UserModel django.contrib.auth.views.UserModel + +# Using the definitions from `dict` (from typeshed) +django.contrib.sessions.backends.base.SessionBase.get +django.contrib.sessions.backends.base.SessionBase.setdefault diff --git a/scripts/stubtest/allowlist_todo.txt b/scripts/stubtest/allowlist_todo.txt index bc5e54706..e6af69e58 100644 --- a/scripts/stubtest/allowlist_todo.txt +++ b/scripts/stubtest/allowlist_todo.txt @@ -471,9 +471,6 @@ django.contrib.redirects.models.Redirect.new_path django.contrib.redirects.models.Redirect.old_path django.contrib.redirects.models.Redirect.site django.contrib.redirects.models.Redirect.site_id -django.contrib.sessions.backends.base.SessionBase.get -django.contrib.sessions.backends.base.SessionBase.setdefault -django.contrib.sessions.backends.base.SessionBase.update django.contrib.sessions.backends.signed_cookies.SessionStore.exists django.contrib.sessions.base_session.AbstractBaseSession.expire_date django.contrib.sessions.base_session.AbstractBaseSession.get_next_by_expire_date diff --git a/scripts/stubtest/allowlist_todo_django51.txt b/scripts/stubtest/allowlist_todo_django51.txt index b64905951..ae8772271 100644 --- a/scripts/stubtest/allowlist_todo_django51.txt +++ b/scripts/stubtest/allowlist_todo_django51.txt @@ -98,65 +98,6 @@ django.contrib.postgres.operations.CreateExtension.category django.contrib.postgres.operations.RemoveCollation.category django.contrib.postgres.operations.RemoveIndexConcurrently.category django.contrib.postgres.operations.ValidateConstraint.category -django.contrib.sessions.backends.base.SessionBase.aclear_expired -django.contrib.sessions.backends.base.SessionBase.acreate -django.contrib.sessions.backends.base.SessionBase.acycle_key -django.contrib.sessions.backends.base.SessionBase.adelete -django.contrib.sessions.backends.base.SessionBase.adelete_test_cookie -django.contrib.sessions.backends.base.SessionBase.aexists -django.contrib.sessions.backends.base.SessionBase.aflush -django.contrib.sessions.backends.base.SessionBase.aget -django.contrib.sessions.backends.base.SessionBase.aget_expire_at_browser_close -django.contrib.sessions.backends.base.SessionBase.aget_expiry_age -django.contrib.sessions.backends.base.SessionBase.aget_expiry_date -django.contrib.sessions.backends.base.SessionBase.ahas_key -django.contrib.sessions.backends.base.SessionBase.aitems -django.contrib.sessions.backends.base.SessionBase.akeys -django.contrib.sessions.backends.base.SessionBase.aload -django.contrib.sessions.backends.base.SessionBase.apop -django.contrib.sessions.backends.base.SessionBase.asave -django.contrib.sessions.backends.base.SessionBase.aset -django.contrib.sessions.backends.base.SessionBase.aset_expiry -django.contrib.sessions.backends.base.SessionBase.aset_test_cookie -django.contrib.sessions.backends.base.SessionBase.asetdefault -django.contrib.sessions.backends.base.SessionBase.atest_cookie_worked -django.contrib.sessions.backends.base.SessionBase.aupdate -django.contrib.sessions.backends.base.SessionBase.avalues -django.contrib.sessions.backends.cache.SessionStore.acache_key -django.contrib.sessions.backends.cache.SessionStore.aclear_expired -django.contrib.sessions.backends.cache.SessionStore.acreate -django.contrib.sessions.backends.cache.SessionStore.adelete -django.contrib.sessions.backends.cache.SessionStore.aexists -django.contrib.sessions.backends.cache.SessionStore.aload -django.contrib.sessions.backends.cache.SessionStore.asave -django.contrib.sessions.backends.cached_db.SessionStore.acache_key -django.contrib.sessions.backends.cached_db.SessionStore.adelete -django.contrib.sessions.backends.cached_db.SessionStore.aexists -django.contrib.sessions.backends.cached_db.SessionStore.aflush -django.contrib.sessions.backends.cached_db.SessionStore.aload -django.contrib.sessions.backends.cached_db.SessionStore.asave -django.contrib.sessions.backends.cached_db.logger -django.contrib.sessions.backends.db.SessionStore.aclear_expired -django.contrib.sessions.backends.db.SessionStore.acreate -django.contrib.sessions.backends.db.SessionStore.acreate_model_instance -django.contrib.sessions.backends.db.SessionStore.adelete -django.contrib.sessions.backends.db.SessionStore.aexists -django.contrib.sessions.backends.db.SessionStore.aload -django.contrib.sessions.backends.db.SessionStore.asave -django.contrib.sessions.backends.file.SessionStore.aclear_expired -django.contrib.sessions.backends.file.SessionStore.acreate -django.contrib.sessions.backends.file.SessionStore.adelete -django.contrib.sessions.backends.file.SessionStore.aexists -django.contrib.sessions.backends.file.SessionStore.aload -django.contrib.sessions.backends.file.SessionStore.asave -django.contrib.sessions.backends.file.SessionStore.clean -django.contrib.sessions.backends.signed_cookies.SessionStore.aclear_expired -django.contrib.sessions.backends.signed_cookies.SessionStore.acreate -django.contrib.sessions.backends.signed_cookies.SessionStore.acycle_key -django.contrib.sessions.backends.signed_cookies.SessionStore.adelete -django.contrib.sessions.backends.signed_cookies.SessionStore.aexists -django.contrib.sessions.backends.signed_cookies.SessionStore.aload -django.contrib.sessions.backends.signed_cookies.SessionStore.asave django.core.checks.templates.E001 django.core.checks.templates.E002 django.core.checks.templates.W003