pylint-django icon indicating copy to clipboard operation
pylint-django copied to clipboard

False positive: unexpected-keyword-arg, timespec in isoformat calls of DateTimeField values

Open koniiiik opened this issue 2 years ago • 3 comments

Here's a weird corner case that I've run into in our code base, where if a model instance is created through direct instantiation, subsequent calls to isoformat with a timespec are flagged, even though this works fine when instantiating through ModelClass.objects.create(). Here's an example (settings.py is an empty file):

$ cat datetimefield.py
# pylint: disable=C
from django.db import models


class A(models.Model):
    field = models.DateTimeField(auto_now=True)


x = A()
x.save()
x.field.isoformat(timespec='seconds')

y = A.objects.create()
y.field.isoformat(timespec='seconds')

$ pylint --load-plugins=pylint_django --django-settings-module=settings datetimefield.py 
************* Module datetimefield
datetimefield.py:11:0: E1123: Unexpected keyword argument 'timespec' in method call (unexpected-keyword-arg)

-----------------------------------
Your code has been rated at 3.75/10

Here's the environment (I simply installed prospector and django):

asgiref==3.6.0
astroid==2.14.2
dill==0.3.6
Django==4.1.7
dodgy==0.2.1
flake8==5.0.4
flake8-polyfill==1.0.2
gitdb==4.0.10
GitPython==3.1.31
isort==5.12.0
lazy-object-proxy==1.9.0
mccabe==0.7.0
packaging==23.0
pep8-naming==0.10.0
platformdirs==3.0.0
poetry-semver==0.1.0
prospector==1.9.0
pycodestyle==2.9.1
pydocstyle==6.3.0
pyflakes==2.5.0
pylint==2.16.2
pylint-celery==0.3
pylint-django==2.5.3
pylint-flask==0.6
pylint-plugin-utils==0.7
PyYAML==6.0
requirements-detector==1.1.0
setoptconf-tmp==0.3.1
smmap==5.0.0
snowballstemmer==2.2.0
sqlparse==0.4.3
toml==0.10.2
tomli==2.0.1
tomlkit==0.11.6
typing_extensions==4.5.0
wrapt==1.14.1

koniiiik avatar Feb 21 '23 14:02 koniiiik