Skip to content

Class-based view mixin attributes have incompatible types #152

Closed
@treyhunner

Description

@treyhunner

With the following class-based view mixin and a view that inherits from it as well as DetailView, the model and context_object_name attributes are picked up as having incorrect types:

from django.views.generic import DetailView

class ExerciseDetailMixin:
    context_object_name = "exercise"
    model = Exercise

class ExerciseDetailView(ExerciseDetailMixin, DetailView):
    pass
exercises/views.py:95:1: error: Definition of "model" in base class "ExerciseDetailMixin" is incompatible with definition in base class "SingleObjectTemplateResponseMixin"
exercises/views.py:95:1: error: Definition of "model" in base class "ExerciseDetailMixin" is incompatible with definition in base class "SingleObjectMixin"
exercises/views.py:95:1: error: Definition of "context_object_name" in base class "ExerciseDetailMixin" is incompatible with definition in base class "SingleObjectMixin"

Here are their revealed types:

exercises/views.py:100:1: note: Revealed type is 'def (*_args: Any, **_kwds: Any) -> exercises.models.Exercise'
exercises/views.py:101:1: note: Revealed type is 'builtins.str'

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