typeddjango / djangorestframework-stubs

PEP-484 stubs for django-rest-framework
MIT License
454 stars 118 forks source link

Pylance doesn't allow a ModelSerializer to have a Meta class #689

Open ataylor32 opened 3 weeks ago

ataylor32 commented 3 weeks ago

This is my code:

from rest_framework import serializers

from ..models import FAQ

class FAQSerializer(serializers.ModelSerializer):
    class Meta:
        model = FAQ
        fields = (
            "id",
            "question",
            "answer",
        )

When I open the above file in Visual Studio Code (latest version, which is 1.95.0), Meta is underlined in red. Hovering over it shows the following error:

"Meta" overrides symbol of same name in class "ModelSerializer"
  "project.faqs.api.serializers.FAQSerializer.Meta" is not assignable to "rest_framework.serializers.ModelSerializer.Meta"
  Type "type[project.faqs.api.serializers.FAQSerializer.Meta]" is not assignable to type "type[rest_framework.serializers.ModelSerializer.Meta]" Pylance(reportIncompatibleVariableOverride)
serializers.pyi(197, 11): Overridden symbol

I'm using djangorestframework-stubs==3.15.1. Am I doing something wrong?