You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm having issues with MyPy and class based views (but also my custom HttpRequest for authenticated users as shown in the docs):
With this code:
from django.contrib.auth.models import User
from django.http import HttpRequest
class AuthenticatedHttpRequest(HttpRequest):
user: User
The error I get
´Covariant override of a mutable attribute (base class "HttpRequest" defined the type as "User | AnonymousUser", expression has type "User")`
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi all,
I'm having issues with MyPy and class based views (but also my custom HttpRequest for authenticated users as shown in the docs):
With this code:
The error I get
´Covariant override of a mutable attribute (base class "HttpRequest" defined the type as "User | AnonymousUser", expression has type "User")`
The mypy config I use is the following:
I could disable the mutable-override check but the override seems sound to me (I'm strictly returning one of the values of the union type)
Beta Was this translation helpful? Give feedback.
All reactions