Open
Description
Bug report
What's wrong
These are from the Request object in the stubbs.
def user(self) -> AbstractBaseUser | AnonymousUser: ...
@user.setter
def user(self, value: AbstractBaseUser | AnonymousUser) -> None: ...
However i have a different auth model defined in my settings.py
called CustomUser
AUTH_USER_MODEL = "base.CustomUser"
Is there a way to get this typing correct.
Use case error:
user = self.request.user
if user.can_manage():
return queryset
products/views.py:145: error: Item "AnonymousUser" of "AbstractBaseUser | AnonymousUser" has no attribute "can_manage" [union-attr]
Furthermore, if the permission classes dont allow "AnonymousUser" can we type narrow that somehow? (Like in django-stubs
How can I create a HttpRequest that's guaranteed to have an authenticated user?
How is that should be
It should be narrowed to just my CustomUser
TL;DR:
- How can i only see
CustomUser
instead ofAbstractBaseUser | AnonymousUser
System information
- OS: MAC
python
version: 3.11django
version: 4.2mypy
version: 1.7.1django-stubs
version: (latest)