AuthenticatedHttpRequest use for LoginRequiredMixin
As described in https://github.com/typeddjango/django-stubs#how-can-i-create-a-httprequest-thats-guaranteed-to-have-an-authenticated-user one could use AuthenticatedHttpRequest annotate request in function views with @login_required decorators.
But how can this be adapted to class views with LoginRequiredMixin?
Any idea?
You can change the type hint for the request argument to AuthenticatedHttpRequest.
class SomeAPIView(...):
def get(self, request: AuthenticatedHttpRequest, ...)
Sorry for the late reply ...
Finally I got to the point to refactor my app and to try your solution. But I get the following error message from mypy v1.8.0
my_app/views/__init__.py:70: error: Argument 1 of "get" is incompatible with supertype "ProcessFormView"; supertype defines the argument type as "HttpRequest" [override]
def get(self, request: AuthenticatedHttpRequest, *args: Any, **kwargs: Any) -> HttpResponse:
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
class User(AbstractUser):
...
class AuthenticatedHttpRequest(HttpRequest):
user: User
Indeed. My bad.
I unfortunately don't know any solution except explicitly cast()ing request to an authenticated_request in the method body.