Skip to content

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

Open
@ataylor32

Description

@ataylor32

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions