Skip to content

Commit

Permalink
Type get_response with a callback protocol.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
PIG208 committed Aug 5, 2022
1 parent eca7c77 commit 23ed131
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions django-stubs/utils/deprecation.pyi
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -27,7 +27,8 @@ class DeprecationInstanceCheck(type):
deprecation_warning: Type[Warning]
def __instancecheck__(self, instance: Any): ...

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

class MiddlewareMixin:
get_response: GetResponseCallable = ...
Expand Down

0 comments on commit 23ed131

Please sign in to comment.