flake8-django
flake8-django copied to clipboard
Violations missed in sub-classes of abstract class
I just started using flake8-django
to evaluate it. Thanks for this great project!
I have the following models:
class AbstractModel(models.Model):
class Meta:
abstract = True
name = models.CharField(_('Name'), max_length=100) [DJ12]
code = models.CharField(_('Code'), max_length=10, unique=True) [DJ12]
def __str__(self) -> str:
return self.name
class A(AbstractModel):
class Meta:
ordering = ['name']
some_url = models.URLField('Some URL')
Since there are no line numbers I added the violations at the end of the lines.
Expected Result:
class A
should also have DJ12 as well as DJ10 and DJ11. If the super class is changed to models.Model
these appear.
Also, if the definition for __str__
in AbstractModel
is removed, there is no violation DJ08
reported for A
.
A side comment/question: Instead of showing the violation for the wrong placement of Meta
on each field, would it be possible to place the violation on Meta
instead?
Relates to #85 which is a generic issue for this issue.
I briefly played around with this and it seems to me that the only way to detect this properly is to track the class hierarchy to traverse the bases in order to consistently determine whether a class is a model or not. @rocioar is this correct or is there any other way to do this?