Skip to content

BaseModelAdmin should be a generic class #482

Closed
@fancysnake

Description

@fancysnake

Bug report

What's wrong

I have a class inheriting from BaseModelAdmin and a method delete_model defined as such:

def delete_model(self, request: HttpRequest, obj: AgendaItem) -> None:

AgendaItem is a Django model

However, mypy raises an error:

app/chronology/admin.py: note: In member "delete_model" of class "AgendaItemAdmin":
app/chronology/admin.py:376: error: Argument 2 of "delete_model" is
incompatible with supertype "ModelAdmin"; supertype defines the argument type as
"Model"  [override]
        def delete_model(self, request: HttpRequest, obj: AgendaItem) -> N...
        ^

because in stubs this function is defined as:

def delete_model(self, request: HttpRequest, obj: Model) -> None: ...

How is that should be

The solution is to make BaseModelAdmin a generic class with model type variable.

System information

  • OS: ArchLinux
  • python version: 3.8.6
  • django version: 3.1.2
  • mypy version: 0.782
  • django-stubs version: 1.6.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedExtra attention is needed

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions