Skip to content

Commit 45d4851

Browse files
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
1 parent 7aa4f48 commit 45d4851

File tree

10 files changed

+22
-19
lines changed

10 files changed

+22
-19
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from django.core.exceptions import SuspiciousOperation
1+
from django.core.exceptions import BadRequest, SuspiciousOperation
22

33
class InvalidSessionKey(SuspiciousOperation): ...
44
class SuspiciousSession(SuspiciousOperation): ...
5+
class SessionInterrupted(BadRequest): ...

django-stubs/core/cache/__init__.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ from django.utils.connection import BaseConnectionHandler
55
from .backends.base import BaseCache as BaseCache
66
from .backends.base import CacheKeyWarning as CacheKeyWarning
77
from .backends.base import InvalidCacheBackendError as InvalidCacheBackendError
8+
from .backends.base import InvalidCacheKey as InvalidCacheKey
89

910
DEFAULT_CACHE_ALIAS: str
1011

django-stubs/core/cache/backends/db.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Any
1+
from typing import Any, ClassVar
22

33
from django.core.cache.backends.base import BaseCache
44
from django.utils.functional import _StrOrPromise
@@ -20,4 +20,5 @@ class BaseDatabaseCache(BaseCache):
2020
cache_model_class: Any
2121
def __init__(self, table: str, params: dict[str, Any]) -> None: ...
2222

23-
class DatabaseCache(BaseDatabaseCache): ...
23+
class DatabaseCache(BaseDatabaseCache):
24+
pickle_protocol: ClassVar[int]
Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
from typing import Any
1+
from typing import Any, ClassVar
22

33
from django.core.cache.backends.base import BaseCache
44

55
class FileBasedCache(BaseCache):
6-
cache_suffix: str
6+
cache_suffix: ClassVar[str]
7+
pickle_protocol: ClassVar[int]
78
def __init__(self, dir: str, params: dict[str, Any]) -> None: ...
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
from typing import Any
1+
from typing import Any, ClassVar
22

33
from django.core.cache.backends.base import BaseCache
44

55
class LocMemCache(BaseCache):
6+
pickle_protocol: ClassVar[int]
7+
68
def __init__(self, name: str, params: dict[str, Any]) -> None: ...

django-stubs/core/cache/backends/memcached.pyi

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,16 @@ class BaseMemcachedCache(BaseCache):
1212
library: ModuleType,
1313
value_not_found_exception: type[BaseException],
1414
) -> None: ...
15+
@property
16+
def client_servers(self) -> Sequence[str]: ...
1517

1618
class MemcachedCache(BaseMemcachedCache):
1719
def __init__(self, server: str | Sequence[str], params: dict[str, Any]) -> None: ...
1820

1921
class PyLibMCCache(BaseMemcachedCache):
2022
def __init__(self, server: str | Sequence[str], params: dict[str, Any]) -> None: ...
23+
@property
24+
def client_servers(self) -> list[str]: ...
2125

2226
class PyMemcacheCache(BaseMemcachedCache):
2327
def __init__(self, server: str | Sequence[str], params: dict[str, Any]) -> None: ...

django-stubs/core/checks/templates.pyi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from django.core.checks.messages import Error, Warning
66

77
E001: Error
88
E002: Error
9-
W001: Warning
9+
W003: Warning
1010

1111
def check_setting_app_dirs_loaders(app_configs: Sequence[AppConfig] | None, **kwargs: Any) -> Sequence[Error]: ...
1212
def check_string_if_invalid_is_string(app_configs: Sequence[AppConfig] | None, **kwargs: Any) -> Sequence[Error]: ...

django-stubs/core/exceptions.pyi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class SuspiciousFileOperation(SuspiciousOperation): ...
1616
class DisallowedHost(SuspiciousOperation): ...
1717
class DisallowedRedirect(SuspiciousOperation): ...
1818
class TooManyFieldsSent(SuspiciousOperation): ...
19+
class TooManyFilesSent(SuspiciousOperation): ...
1920
class RequestDataTooBig(SuspiciousOperation): ...
2021
class RequestAborted(Exception): ...
2122
class BadRequest(Exception): ...
@@ -48,4 +49,5 @@ class ValidationError(Exception):
4849
def __iter__(self) -> Iterator[tuple[str, list[str]] | str]: ...
4950

5051
class EmptyResultSet(Exception): ...
52+
class FullResultSet(Exception): ...
5153
class SynchronousOnlyOperation(Exception): ...

scripts/stubtest/allowlist.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,3 +110,6 @@ django.views.generic.edit.BaseDeleteView.form_class
110110
# We still keep them in stubs to be a bit more backward compatible.
111111
# RemovedInDjango40:
112112
django.middleware.csrf.REASON_BAD_TOKEN
113+
114+
# RemovedInDjango41
115+
django.core.cache.backends.memcached.MemcachedCache

scripts/stubtest/allowlist_todo.txt

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -795,7 +795,6 @@ django.contrib.sessions.base_session.AbstractBaseSession.get_previous_by_expire_
795795
django.contrib.sessions.base_session.AbstractBaseSession.session_data
796796
django.contrib.sessions.base_session.AbstractBaseSession.session_key
797797
django.contrib.sessions.base_session.BaseSessionManager.__slotnames__
798-
django.contrib.sessions.exceptions.SessionInterrupted
799798
django.contrib.sessions.management.commands.clearsessions.Command.handle
800799
django.contrib.sessions.models.Session.expire_date
801800
django.contrib.sessions.models.Session.get_next_by_expire_date
@@ -818,19 +817,8 @@ django.contrib.staticfiles.finders.FileSystemFinder.__init__
818817
django.contrib.staticfiles.management.commands.collectstatic
819818
django.contrib.staticfiles.management.commands.findstatic.Command.handle_label
820819
django.contrib.staticfiles.storage
821-
django.core.cache.InvalidCacheKey
822-
django.core.cache.backends.db.DatabaseCache.pickle_protocol
823-
django.core.cache.backends.filebased.FileBasedCache.pickle_protocol
824-
django.core.cache.backends.locmem.LocMemCache.pickle_protocol
825-
django.core.cache.backends.memcached.BaseMemcachedCache.client_servers
826-
django.core.cache.backends.memcached.MemcachedCache
827-
django.core.cache.backends.memcached.PyLibMCCache.client_servers
828820
django.core.cache.cache
829821
django.core.checks.registry.CheckRegistry.register
830-
django.core.checks.templates.W001
831-
django.core.checks.templates.W003
832-
django.core.exceptions.FullResultSet
833-
django.core.exceptions.TooManyFilesSent
834822
django.core.files.File.__next__
835823
django.core.files.File.size
836824
django.core.files.base.ContentFile.size

0 commit comments

Comments
 (0)