Skip to content

Commit

Permalink
Django core cache (#1774)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
UnknownPlatypus committed Oct 17, 2023
1 parent 7aa4f48 commit 45d4851
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 19 deletions.
3 changes: 2 additions & 1 deletion django-stubs/contrib/sessions/exceptions.pyi
Original file line number Diff line number Diff line change
@@ -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): ...
1 change: 1 addition & 0 deletions django-stubs/core/cache/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions django-stubs/core/cache/backends/db.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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]
5 changes: 3 additions & 2 deletions django-stubs/core/cache/backends/filebased.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
4 changes: 3 additions & 1 deletion django-stubs/core/cache/backends/locmem.pyi
Original file line number Diff line number Diff line change
@@ -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: ...
4 changes: 4 additions & 0 deletions django-stubs/core/cache/backends/memcached.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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: ...
2 changes: 1 addition & 1 deletion django-stubs/core/checks/templates.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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]: ...
Expand Down
2 changes: 2 additions & 0 deletions django-stubs/core/exceptions.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -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): ...
Expand Down Expand Up @@ -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): ...
3 changes: 3 additions & 0 deletions scripts/stubtest/allowlist.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 0 additions & 12 deletions scripts/stubtest/allowlist_todo.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 45d4851

Please sign in to comment.