From 45d4851b5e1cbaf30dfccd07468ea0433b15746c Mon Sep 17 00:00:00 2001 From: Thibaut Decombe <68703331+UnknownPlatypus@users.noreply.github.com> Date: Tue, 17 Oct 2023 21:15:14 +0200 Subject: [PATCH] Django core cache (#1774) * Add missing `pickle_protocol` stubs * Fix `django.core.cache.backends.memcached` types * Add missing exceptions classes * Fix missing`InvalidCacheKey` re-export * Fix template warnings * Fix after CR --- django-stubs/contrib/sessions/exceptions.pyi | 3 ++- django-stubs/core/cache/__init__.pyi | 1 + django-stubs/core/cache/backends/db.pyi | 5 +++-- django-stubs/core/cache/backends/filebased.pyi | 5 +++-- django-stubs/core/cache/backends/locmem.pyi | 4 +++- django-stubs/core/cache/backends/memcached.pyi | 4 ++++ django-stubs/core/checks/templates.pyi | 2 +- django-stubs/core/exceptions.pyi | 2 ++ scripts/stubtest/allowlist.txt | 3 +++ scripts/stubtest/allowlist_todo.txt | 12 ------------ 10 files changed, 22 insertions(+), 19 deletions(-) diff --git a/django-stubs/contrib/sessions/exceptions.pyi b/django-stubs/contrib/sessions/exceptions.pyi index 9ec91907a..194592ea9 100644 --- a/django-stubs/contrib/sessions/exceptions.pyi +++ b/django-stubs/contrib/sessions/exceptions.pyi @@ -1,4 +1,5 @@ -from django.core.exceptions import SuspiciousOperation +from django.core.exceptions import BadRequest, SuspiciousOperation class InvalidSessionKey(SuspiciousOperation): ... class SuspiciousSession(SuspiciousOperation): ... +class SessionInterrupted(BadRequest): ... diff --git a/django-stubs/core/cache/__init__.pyi b/django-stubs/core/cache/__init__.pyi index 24a8d8fa1..ed6f98eca 100644 --- a/django-stubs/core/cache/__init__.pyi +++ b/django-stubs/core/cache/__init__.pyi @@ -5,6 +5,7 @@ from django.utils.connection import BaseConnectionHandler from .backends.base import BaseCache as BaseCache from .backends.base import CacheKeyWarning as CacheKeyWarning from .backends.base import InvalidCacheBackendError as InvalidCacheBackendError +from .backends.base import InvalidCacheKey as InvalidCacheKey DEFAULT_CACHE_ALIAS: str diff --git a/django-stubs/core/cache/backends/db.pyi b/django-stubs/core/cache/backends/db.pyi index 38de15b5e..80c67aa15 100644 --- a/django-stubs/core/cache/backends/db.pyi +++ b/django-stubs/core/cache/backends/db.pyi @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, ClassVar from django.core.cache.backends.base import BaseCache from django.utils.functional import _StrOrPromise @@ -20,4 +20,5 @@ class BaseDatabaseCache(BaseCache): cache_model_class: Any def __init__(self, table: str, params: dict[str, Any]) -> None: ... -class DatabaseCache(BaseDatabaseCache): ... +class DatabaseCache(BaseDatabaseCache): + pickle_protocol: ClassVar[int] diff --git a/django-stubs/core/cache/backends/filebased.pyi b/django-stubs/core/cache/backends/filebased.pyi index d4159de83..956a47703 100644 --- a/django-stubs/core/cache/backends/filebased.pyi +++ b/django-stubs/core/cache/backends/filebased.pyi @@ -1,7 +1,8 @@ -from typing import Any +from typing import Any, ClassVar from django.core.cache.backends.base import BaseCache class FileBasedCache(BaseCache): - cache_suffix: str + cache_suffix: ClassVar[str] + pickle_protocol: ClassVar[int] def __init__(self, dir: str, params: dict[str, Any]) -> None: ... diff --git a/django-stubs/core/cache/backends/locmem.pyi b/django-stubs/core/cache/backends/locmem.pyi index 3a158d074..c2634b004 100644 --- a/django-stubs/core/cache/backends/locmem.pyi +++ b/django-stubs/core/cache/backends/locmem.pyi @@ -1,6 +1,8 @@ -from typing import Any +from typing import Any, ClassVar from django.core.cache.backends.base import BaseCache class LocMemCache(BaseCache): + pickle_protocol: ClassVar[int] + def __init__(self, name: str, params: dict[str, Any]) -> None: ... diff --git a/django-stubs/core/cache/backends/memcached.pyi b/django-stubs/core/cache/backends/memcached.pyi index 06cad1818..aff2348c1 100644 --- a/django-stubs/core/cache/backends/memcached.pyi +++ b/django-stubs/core/cache/backends/memcached.pyi @@ -12,12 +12,16 @@ class BaseMemcachedCache(BaseCache): library: ModuleType, value_not_found_exception: type[BaseException], ) -> None: ... + @property + def client_servers(self) -> Sequence[str]: ... class MemcachedCache(BaseMemcachedCache): def __init__(self, server: str | Sequence[str], params: dict[str, Any]) -> None: ... class PyLibMCCache(BaseMemcachedCache): def __init__(self, server: str | Sequence[str], params: dict[str, Any]) -> None: ... + @property + def client_servers(self) -> list[str]: ... class PyMemcacheCache(BaseMemcachedCache): def __init__(self, server: str | Sequence[str], params: dict[str, Any]) -> None: ... diff --git a/django-stubs/core/checks/templates.pyi b/django-stubs/core/checks/templates.pyi index 9bfee7c39..163a550f7 100644 --- a/django-stubs/core/checks/templates.pyi +++ b/django-stubs/core/checks/templates.pyi @@ -6,7 +6,7 @@ from django.core.checks.messages import Error, Warning E001: Error E002: Error -W001: Warning +W003: Warning def check_setting_app_dirs_loaders(app_configs: Sequence[AppConfig] | None, **kwargs: Any) -> Sequence[Error]: ... def check_string_if_invalid_is_string(app_configs: Sequence[AppConfig] | None, **kwargs: Any) -> Sequence[Error]: ... diff --git a/django-stubs/core/exceptions.pyi b/django-stubs/core/exceptions.pyi index 303de0c86..762850123 100644 --- a/django-stubs/core/exceptions.pyi +++ b/django-stubs/core/exceptions.pyi @@ -16,6 +16,7 @@ class SuspiciousFileOperation(SuspiciousOperation): ... class DisallowedHost(SuspiciousOperation): ... class DisallowedRedirect(SuspiciousOperation): ... class TooManyFieldsSent(SuspiciousOperation): ... +class TooManyFilesSent(SuspiciousOperation): ... class RequestDataTooBig(SuspiciousOperation): ... class RequestAborted(Exception): ... class BadRequest(Exception): ... @@ -48,4 +49,5 @@ class ValidationError(Exception): def __iter__(self) -> Iterator[tuple[str, list[str]] | str]: ... class EmptyResultSet(Exception): ... +class FullResultSet(Exception): ... class SynchronousOnlyOperation(Exception): ... diff --git a/scripts/stubtest/allowlist.txt b/scripts/stubtest/allowlist.txt index 4f3a7c3c0..57feee188 100644 --- a/scripts/stubtest/allowlist.txt +++ b/scripts/stubtest/allowlist.txt @@ -110,3 +110,6 @@ django.views.generic.edit.BaseDeleteView.form_class # We still keep them in stubs to be a bit more backward compatible. # RemovedInDjango40: django.middleware.csrf.REASON_BAD_TOKEN + +# RemovedInDjango41 +django.core.cache.backends.memcached.MemcachedCache diff --git a/scripts/stubtest/allowlist_todo.txt b/scripts/stubtest/allowlist_todo.txt index d12167940..308a5ee20 100644 --- a/scripts/stubtest/allowlist_todo.txt +++ b/scripts/stubtest/allowlist_todo.txt @@ -795,7 +795,6 @@ django.contrib.sessions.base_session.AbstractBaseSession.get_previous_by_expire_ django.contrib.sessions.base_session.AbstractBaseSession.session_data django.contrib.sessions.base_session.AbstractBaseSession.session_key django.contrib.sessions.base_session.BaseSessionManager.__slotnames__ -django.contrib.sessions.exceptions.SessionInterrupted django.contrib.sessions.management.commands.clearsessions.Command.handle django.contrib.sessions.models.Session.expire_date django.contrib.sessions.models.Session.get_next_by_expire_date @@ -818,19 +817,8 @@ django.contrib.staticfiles.finders.FileSystemFinder.__init__ django.contrib.staticfiles.management.commands.collectstatic django.contrib.staticfiles.management.commands.findstatic.Command.handle_label django.contrib.staticfiles.storage -django.core.cache.InvalidCacheKey -django.core.cache.backends.db.DatabaseCache.pickle_protocol -django.core.cache.backends.filebased.FileBasedCache.pickle_protocol -django.core.cache.backends.locmem.LocMemCache.pickle_protocol -django.core.cache.backends.memcached.BaseMemcachedCache.client_servers -django.core.cache.backends.memcached.MemcachedCache -django.core.cache.backends.memcached.PyLibMCCache.client_servers django.core.cache.cache django.core.checks.registry.CheckRegistry.register -django.core.checks.templates.W001 -django.core.checks.templates.W003 -django.core.exceptions.FullResultSet -django.core.exceptions.TooManyFilesSent django.core.files.File.__next__ django.core.files.File.size django.core.files.base.ContentFile.size