pylint-django
pylint-django copied to clipboard
False positive when field type inherits from FileField
With the following code:
from django.db import models
class ExtraFileField(models.FileField):
pass
class Foo(models.Model):
document = ExtraFileField(verbose_name='whatever')
I get warnings:
test.py:7:15: E1123: Unexpected keyword argument 'verbose_name' in constructor call (unexpected-keyword-arg) test.py:7:15: E1120: No value for argument 'instance' in constructor call (no-value-for-parameter) test.py:7:15: E1120: No value for argument 'field' in constructor call (no-value-for-parameter) test.py:7:15: E1120: No value for argument 'name' in constructor call (no-value-for-parameter)
I believe these are incorrect. If I remove the inheritance and instantiate models.FileField rather than ExtraFileField on the model, the warnings go away even though this ought to make no difference.
I notice there are some cases that have special handling for models.FileField, maybe this just needs to be extended to classes that inherit from it?
pip freeze output:
astroid==2.0.4
Django==2.1.1
isort==4.3.4
lazy-object-proxy==1.3.1
mccabe==0.6.1
pkg-resources==0.0.0
pylint==2.1.1
pylint-django==2.0.2
pylint-plugin-utils==0.4
pytz==2018.5
six==1.11.0
typed-ast==1.1.0
wrapt==1.10.11
The same:
from django.db import models
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
class AbstractPage(models.Model):
updated_at = models.DateTimeField(
default=timezone.now,
verbose_name=_('Date updated'),
)
published_at = models.DateTimeField(
default=timezone.now,
verbose_name=_('First publication date'),
)
class Meta:
abstract = True
class Post(AbstractPage):
@property
def is_updated(self):
published_at = self.published_at.replace(microsecond=0) # line: 101
updated_at = self.updated_at.replace(microsecond=0)
return updated_at > published_at
$ .venv/bin/pylint \
--load-plugins=pylint_django \
--django-settings-module=branch.settings.test \
./branch ./apps
************* Module apps.blog.models
apps/blog/models.py:101:23: E1123: Unexpected keyword argument 'microsecond' in method call (unexpected-keyword-arg)
Bumping, as after 3 years this is still an issue.
I've encountered it with the following package versions:
Django==3.2.9
pylint==2.11.1
pylint-django==2.4.4
pylint-plugin-utils==0.6