typeddjango / djangorestframework-stubs

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

Typing for classes inheriting HyperlinkedIdentityField #537

Closed Alexerson closed 6 months ago

Alexerson commented 8 months ago

It seems that the following changes introduced a bug: https://github.com/typeddjango/djangorestframework-stubs/commit/133e572f08c83c5048a88891686d399e496812f0

It’s possible to not pass any view_name to a HyperlinkedRelatedField if you create a subclass that will define the view_name directly.

For instance:

class BookField(serializers.HyperlinkedRelatedField):
    view_name = 'book-detail'

    def get_queryset(self):
        return Book.objects.all()

is valid. Right now mypy wrongfully complains with:

error: Missing positional argument "view_name" in call to "BookField"  [call-arg]