Repository: typeddjango/djangorestframework-stubs (language: python)

Issue:
New mypy failures on `djangorestframework-stubs` after `django-stubs` update
```

Run mypy --cache-dir=/dev/null --no-incremental rest_framework-stubs
rest_framework-stubs/authtoken/models.pyi:16: error: Name "pk" already defined (possibly by an import)
rest_framework-stubs/authtoken/models.pyi:17: error: Cannot override writeable attribute with read-only property
rest_framework-stubs/request.pyi:71: error: Signature of "user" incompatible with supertype "HttpRequest"
rest_framework-stubs/request.pyi:71: note:      Superclass:
rest_framework-stubs/request.pyi:71: note:          Union[User, AnonymousUser]
rest_framework-stubs/request.pyi:71: note:      Subclass:
rest_framework-stubs/request.pyi:71: note:          Union[AbstractBaseUser, AnonymousUser]
Found 3 errors in 2 files (checked 68 source files)
```

cc @flaeppe 

Looks like that it fails because of our recent User plugin change.


Discussion / hints:
Right, yeah, we probably want use the same type of setup here as in `django-stubs`. I _think_ it'll work to just import and use `django.contrib.auth.base_user._UserModel`.

I suppose any kind of third party working with the configured user would like to benefit from what we declared as `_UserModel`, so there might also be a use case to move it to `django-stubs-ext` and import from there.

Fix patch:
diff --git a/rest_framework-stubs/request.pyi b/rest_framework-stubs/request.pyi
index 3caf8da4..14324b81 100644
--- a/rest_framework-stubs/request.pyi
+++ b/rest_framework-stubs/request.pyi
@@ -4,7 +4,7 @@ from contextlib import AbstractContextManager, contextmanager
 from types import TracebackType
 from typing import Any
 
-from django.contrib.auth.base_user import AbstractBaseUser
+from django.contrib.auth.base_user import AbstractBaseUser, _UserModel
 from django.contrib.auth.models import AnonymousUser
 from django.http import HttpRequest
 from django.http.request import _ImmutableQueryDict
@@ -69,9 +69,9 @@ class Request(HttpRequest):
     @property
     def data(self) -> dict[str, Any]: ...
     @property
-    def user(self) -> AbstractBaseUser | AnonymousUser: ...
+    def user(self) -> _UserModel | AnonymousUser: ...
     @user.setter
-    def user(self, value: AbstractBaseUser | AnonymousUser) -> None: ...
+    def user(self, value: _UserModel | AnonymousUser) -> None: ...
     @property
     def auth(self) -> Token | Any: ...
     @auth.setter


Test patch:
diff --git a/scripts/stubtest/allowlist.txt b/scripts/stubtest/allowlist.txt
index 42aaa369..d00b68b1 100644
--- a/scripts/stubtest/allowlist.txt
+++ b/scripts/stubtest/allowlist.txt
@@ -32,3 +32,7 @@ rest_framework.serializers.TimeField.__init__
 
 # Ignore @cached_property error "cannot reconcile @property on stub with runtime object"
 rest_framework.serializers.Serializer.fields
+
+# Generated objects:
+rest_framework.authtoken.models.Token@AnnotatedWith
+rest_framework.authtoken.models.TokenProxy@AnnotatedWith