Skip to content

Commit ddecd44

Browse files
committed
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 python/mypy#5485. Signed-off-by: Zixuan James Li <p359101898@gmail.com>
1 parent 702d773 commit ddecd44

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

django-stubs/utils/deprecation.pyi

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

33
from django.http.request import HttpRequest
44
from django.http.response import HttpResponse
@@ -27,7 +27,8 @@ class DeprecationInstanceCheck(type):
2727
deprecation_warning: Type[Warning]
2828
def __instancecheck__(self, instance: Any): ...
2929

30-
GetResponseCallable = Callable[[HttpRequest], HttpResponse]
30+
class GetResponseCallable(Protocol):
31+
def __call__(request: HttpRequest) -> HttpResponse: ...
3132

3233
class MiddlewareMixin:
3334
get_response: GetResponseCallable = ...

0 commit comments

Comments
 (0)