mirror of
https://github.com/davidhalter/django-stubs.git
synced 2025-12-10 22:11:54 +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 = ...
|
||||
def __init__(
|
||||
self,
|
||||
get_response: Optional[Callable] = ...,
|
||||
get_response: Callable = ...,
|
||||
cache_timeout: Optional[float] = ...,
|
||||
page_timeout: Optional[float] = ...,
|
||||
**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.response import HttpResponse
|
||||
@@ -27,9 +27,10 @@ class DeprecationInstanceCheck(type):
|
||||
deprecation_warning: Type[Warning]
|
||||
def __instancecheck__(self, instance: Any): ...
|
||||
|
||||
GetResponseCallable = Callable[[HttpRequest], HttpResponse]
|
||||
class GetResponseCallable(Protocol):
|
||||
def __call__(self, __request: HttpRequest) -> HttpResponse: ...
|
||||
|
||||
class MiddlewareMixin:
|
||||
get_response: Optional[GetResponseCallable] = ...
|
||||
def __init__(self, get_response: Optional[GetResponseCallable] = ...) -> None: ...
|
||||
get_response: GetResponseCallable = ...
|
||||
def __init__(self, get_response: GetResponseCallable = ...) -> None: ...
|
||||
def __call__(self, request: HttpRequest) -> HttpResponse: ...
|
||||
|
||||
Reference in New Issue
Block a user