Description
Hi!
I just updated my version to djangorestframework-simplejwt==5.3.1
and I'm running into several mypy errors that were introduced with the recent typehints PR here: #683
I've looked into it, and there are several incorrect types in this library. Many of them have are arguments/return values which are annotated as Token
, but in reality should be str
or bytes
. Some of them are easy to spot (and should have been caught by mypy when adding the types in the first place). Some of them are more difficult because of the dynamic nature of the library (e.g. AUTH_TOKEN_CLASSES
), but they raise errors when you start writing subclasses for the tokens and backends.
For example, this line passes a Token
object into the underlying jwt
library, which is incorrect (should be str
or bytes
).
djangorestframework-simplejwt/rest_framework_simplejwt/backends.py
Lines 139 to 140 in c791e98
Same thing here, passes a Token
object but it should be str
or bytes
.
djangorestframework-simplejwt/rest_framework_simplejwt/backends.py
Lines 100 to 102 in c791e98
Here, the raw_token
is correctly annotated, but then it's being passed into an AuthToken
initializer which is expecting the argument to be Token
.
djangorestframework-simplejwt/rest_framework_simplejwt/authentication.py
Lines 95 to 103 in c791e98
This initializer is wrong (Why would the token class be initialized with an instance of itself?)
djangorestframework-simplejwt/rest_framework_simplejwt/tokens.py
Lines 30 to 39 in c791e98
Unfortunately, I think fixing these type hints will require significant effort to go through and untangle everything.