pylint-dev / pylint-django

Pylint plugin for improving code analysis for when using Django
Other
596 stars 117 forks source link

"[pylint] Unused argument 'kwargs' [W0613]" when using Signals in model #218

Open thinh9e opened 5 years ago

thinh9e commented 5 years ago

My code:

from django.dispatch import receiver
from django.db.models.signals import post_save

@receiver(post_save, sender=settings.AUTH_USER_MODEL)
def post_save_func(sender, instance, **kwargs):
    ...
    pass

I don't use **kwargs in my function, but **kwargs is a mandatory variable to using post_save. Therefor, I have a warning "[pylint] Unused argument 'kwargs' [W0613]". Can you fix to hide warning in this case? Thanks!

Output $ pip freeze:

astroid==2.1.0
beautifulsoup4==4.7.1
certifi==2018.11.29
chardet==3.0.4
Click==7.0
colorama==0.4.1
colorlover==0.2.1
dash==0.35.1
dash-core-components==0.42.1
dash-html-components==0.13.4
dash-renderer==0.16.1
decorator==4.3.0
Django==2.1.5
djangorestframework==3.9.0
Flask==1.0.2
Flask-Compress==1.4.0
idna==2.8
ipython-genutils==0.2.0
isort==4.3.4
itsdangerous==1.1.0
Jinja2==2.10
jsonschema==2.6.0
jupyter-core==4.4.0
lazy-object-proxy==1.3.1
lxml==4.3.0
MarkupSafe==1.1.0
mccabe==0.6.1
nbformat==4.4.0
numpy==1.15.4
pandas==0.23.4
pandas-datareader==0.7.0
Pillow==5.4.1
plotly==3.5.0
pylint==2.2.2
pylint-django==2.0.5
pylint-plugin-utils==0.4
python-dateutil==2.7.5
pytz==2018.9
requests==2.21.0
retrying==1.3.3
six==1.12.0
soupsieve==1.6.2
stripe==2.17.0
traitlets==4.3.2
urllib3==1.24.1
Werkzeug==0.14.1
wrapt==1.11.0
Qu4tro commented 4 years ago

As an alternative, you can safely use **_kwargs.

JensTimmerman commented 3 years ago

Hi, I'm having the same issue and I'm intrested in working on implementing a fix for this, are there any pointers on how to start working on this?

atodorov commented 3 years ago

@JensTimmerman see ignore_unused_argument_warnings_for_request in augmentations/__init__.py and how it is used. You first need to add a test scenario for this issue, then figure out which one of the core pylint checkers is triggering the warning (look into pylint's source code) and then come up with a solution, similar to the one we already have. (honestly I baffles me why the current one doesn't work).

For a general reference about pylint plugins see https://www.youtube.com/watch?v=3CkSKUNMLJc, the interesting stuff related to checkers & augmentations is at the end, after the Q&A session.

JensTimmerman commented 8 months ago

@atodorov this seems to have been a misuse of the plugin system in pylint, I can reproduce the issue, but I can also fix it by actually using the pylint_django plugin correctly.

pylint --load-plugins=pylint_django test.py --django-settings-module=settings

-------------------------------------------------------------------
Your code has been rated at 10.00/10 (previous run: 1.67/10, +8.33)

pylint test.py
************* Module test
test.py:6:0: W0613: Unused argument 'kwargs' (unused-argument)

-------------------------------------------------------------------
Your code has been rated at 8.33/10 (previous run: 10.00/10, -1.67)