-
-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
protocol for new mixins #302
Comments
What if you specify iirc this is the recommended way of doing by |
Yeah, I tried that too, but it complains that the Mixin is not a subclass of "rest_framework.generics.GenericAPIView[Any]" is not a supertype of its class "app.views.TagModelMixin" [misc] You can make it work by having I ended up implementing a basic protocol:
|
Yes I believe protocols is the only possibility to correctly type mixins. As it is pretty common to use mixins in drf (and django as well), this could be implemented as a helper protocol |
I personally use this snippet: """Type alias for Mixins."""
if TYPE_CHECKING:
GenericViewMixin = GenericAPIView
APIViewMixin = APIView
else:
GenericViewMixin = object
APIViewMixin = object And have my Mixins inherit from the corresponding class. |
It would be nice if we could use the classes already defined in
generics.py
as protocols.For example, if I want to define a new viewset mixin
mypy complains that
TagModelMixin
does not have aget_object
attributeI think the solution is to define a protocol for the api of
GenericAPIView
- which is sort of already defined ingenerics.py
The text was updated successfully, but these errors were encountered: