mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-11 22:41:55 +08:00
Reflect the deprecation of get_response being None. (#1086)
* Reflect the deprecation of get_response being None. Signed-off-by: Zixuan James Li <p359101898@gmail.com> * Type get_response with a callback protocol. Otherwise, calling `self.get_response(request)` in a subclass of `MiddlewareMixin` runs into `Invalid self argument` error. This is a workaround for https://github.com/python/mypy/issues/5485. Signed-off-by: Zixuan James Li <p359101898@gmail.com> Signed-off-by: Zixuan James Li <p359101898@gmail.com>
This commit is contained in:
@@ -27,7 +27,7 @@ class CacheMiddleware(UpdateCacheMiddleware, FetchFromCacheMiddleware):
|
|||||||
cache: BaseCache = ...
|
cache: BaseCache = ...
|
||||||
def __init__(
|
def __init__(
|
||||||
self,
|
self,
|
||||||
get_response: Optional[Callable] = ...,
|
get_response: Callable = ...,
|
||||||
cache_timeout: Optional[float] = ...,
|
cache_timeout: Optional[float] = ...,
|
||||||
page_timeout: Optional[float] = ...,
|
page_timeout: Optional[float] = ...,
|
||||||
**kwargs: Any
|
**kwargs: Any
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
from typing import Any, Callable, Optional, Type
|
from typing import Any, Callable, Optional, Protocol, Type
|
||||||
|
|
||||||
from django.http.request import HttpRequest
|
from django.http.request import HttpRequest
|
||||||
from django.http.response import HttpResponse
|
from django.http.response import HttpResponse
|
||||||
@@ -27,9 +27,10 @@ class DeprecationInstanceCheck(type):
|
|||||||
deprecation_warning: Type[Warning]
|
deprecation_warning: Type[Warning]
|
||||||
def __instancecheck__(self, instance: Any): ...
|
def __instancecheck__(self, instance: Any): ...
|
||||||
|
|
||||||
GetResponseCallable = Callable[[HttpRequest], HttpResponse]
|
class GetResponseCallable(Protocol):
|
||||||
|
def __call__(self, __request: HttpRequest) -> HttpResponse: ...
|
||||||
|
|
||||||
class MiddlewareMixin:
|
class MiddlewareMixin:
|
||||||
get_response: Optional[GetResponseCallable] = ...
|
get_response: GetResponseCallable = ...
|
||||||
def __init__(self, get_response: Optional[GetResponseCallable] = ...) -> None: ...
|
def __init__(self, get_response: GetResponseCallable = ...) -> None: ...
|
||||||
def __call__(self, request: HttpRequest) -> HttpResponse: ...
|
def __call__(self, request: HttpRequest) -> HttpResponse: ...
|
||||||
|
|||||||
Reference in New Issue
Block a user