From 69fc9a48f61b2674a9e11da5ff684d292c9f7bf1 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 31 May 2024 18:47:41 +0200 Subject: [PATCH] Improve `django.middleware` stubs --- django-stubs/middleware/cache.pyi | 12 ++++++------ django-stubs/middleware/gzip.pyi | 3 ++- scripts/stubtest/allowlist_todo.txt | 5 ----- 3 files changed, 8 insertions(+), 12 deletions(-) diff --git a/django-stubs/middleware/cache.pyi b/django-stubs/middleware/cache.pyi index 6f1e2efce..b9f0756ee 100644 --- a/django-stubs/middleware/cache.pyi +++ b/django-stubs/middleware/cache.pyi @@ -1,32 +1,32 @@ -from collections.abc import Callable from typing import Any from django.core.cache import BaseCache from django.http.request import HttpRequest from django.http.response import HttpResponse, HttpResponseBase -from django.utils.deprecation import MiddlewareMixin +from django.utils.deprecation import MiddlewareMixin, _AsyncGetResponseCallable, _GetResponseCallable class UpdateCacheMiddleware(MiddlewareMixin): cache_timeout: float key_prefix: str cache_alias: str - cache: BaseCache + @property + def cache(self) -> BaseCache: ... def process_response(self, request: HttpRequest, response: HttpResponseBase | str) -> HttpResponseBase | str: ... class FetchFromCacheMiddleware(MiddlewareMixin): key_prefix: str cache_alias: str - cache: BaseCache + @property + def cache(self) -> BaseCache: ... def process_request(self, request: HttpRequest) -> HttpResponse | None: ... class CacheMiddleware(UpdateCacheMiddleware, FetchFromCacheMiddleware): key_prefix: str cache_alias: str cache_timeout: float - cache: BaseCache def __init__( self, - get_response: Callable = ..., + get_response: _GetResponseCallable | _AsyncGetResponseCallable, cache_timeout: float | None = ..., page_timeout: float | None = ..., **kwargs: Any, diff --git a/django-stubs/middleware/gzip.pyi b/django-stubs/middleware/gzip.pyi index e25dca8be..e1c10a768 100644 --- a/django-stubs/middleware/gzip.pyi +++ b/django-stubs/middleware/gzip.pyi @@ -1,4 +1,4 @@ -from typing import Any +from typing import Any, ClassVar from django.http.request import HttpRequest from django.http.response import HttpResponseBase @@ -7,4 +7,5 @@ from django.utils.deprecation import MiddlewareMixin re_accepts_gzip: Any class GZipMiddleware(MiddlewareMixin): + max_random_bytes: ClassVar[int] def process_response(self, request: HttpRequest, response: HttpResponseBase) -> HttpResponseBase: ... diff --git a/scripts/stubtest/allowlist_todo.txt b/scripts/stubtest/allowlist_todo.txt index 68b70560e..f22355c00 100644 --- a/scripts/stubtest/allowlist_todo.txt +++ b/scripts/stubtest/allowlist_todo.txt @@ -1354,11 +1354,6 @@ django.http.request.HttpRequest.readlines django.http.request.UploadHandlerList django.http.request.parse_accept_header django.http.response.StreamingHttpResponse.content -django.middleware.cache.CacheMiddleware.__init__ -django.middleware.cache.CacheMiddleware.cache -django.middleware.cache.FetchFromCacheMiddleware.cache -django.middleware.cache.UpdateCacheMiddleware.cache -django.middleware.gzip.GZipMiddleware.max_random_bytes django.template.EngineHandler.__init__ django.template.Library.filter_function django.template.Library.simple_tag