Skip to content

DJ008 incorrectly reporting missing __str__ method for abstract class with type annotations #19154

@CarrotManMatt

Description

@CarrotManMatt

Summary

When a Django model class is marked as abstract the lack of a __str__ method is not flagged. This is correct behaviour.

from django.db import models

class Foo(models.Model)
    class Meta:
        abstract = True

When a type annotation is added to the meta class, the identification of the model being abstract is lost, so the DJ008 diagnostic incorrectly occurs.

from typing import ClassVar
from django.db import models
from django_stubs_ext.db.models import TypedModelMeta


class Foo(models.Model):
    class Meta(TypedModelMeta):
        abstract: ClassVar[bool] = True

Version

0.12.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinghelp wantedContributions especially welcomeruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions