typeddjango / djangorestframework-stubs

PEP-484 stubs for django-rest-framework
MIT License
439 stars 115 forks source link

GenericAPIView is missing a typed get_queryset() method #489

Open Kangaroux opened 11 months ago

Kangaroux commented 11 months ago

https://github.com/typeddjango/djangorestframework-stubs/blob/master/rest_framework-stubs/generics.pyi#L33

The missing get_queryset() causes any call to super().get_queryset() to be typed as QuerySet[Any, Any].

# Revealed type is "django.db.models.query._QuerySet[Any, Any]"
reveal_type(super().get_queryset())
sterliakov commented 11 months ago

It is added just a few lines above via mixin:

https://github.com/typeddjango/djangorestframework-stubs/blob/133e572f08c83c5048a88891686d399e496812f0/rest_framework-stubs/generics.pyi#L22

Are you sure that you inherit e.g. GenericAPIView[MyModel] and not simply GenericAPIView? It's exactly the use of type variable here - you must pass a related model type.

Kangaroux commented 11 months ago

@sterliakov You're right, I wasn't using that. It would be good to update the FAQ in the readme to include this example as well (there's one already for serializers).