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 <p359101898@gmail.com>
  • Loading branch information
PIG208 committed Aug 5, 2022
1 parent b73da5c commit 8f07893
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion django-stubs/utils/deprecation.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ class DeprecationInstanceCheck(type):
deprecation_warning: Type[Warning]
def __instancecheck__(self, instance: Any): ...

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

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

0 comments on commit 8f07893

Please sign in to comment.