JivanAmara
JivanAmara

Reputation: 1115

Quieting pylint false-positives when using django

I'd like to sanely quiet a few pylint errors when using Django. The two that are causing the greatest irritation are when deriving from django.db.models.Model and accessing objects, and django.test.TestCase. In the first, pylint complains about any code that uses the attribute 'objects', saying it isn't a member. In the second, after adding seven tests to a test case, it complains about too many public methods (I'm guessing that TestCase has fourteen)

I know the first part of this is a duplicate of question 115977, but that question is a little old and none of the solutions are very good so I thought I'd poke the issue.

I don't want to simply suppress the complaints in pylint, as I like to see them in other circumstances.

Upvotes: 12

Views: 4024

Answers (3)

Tal Weiss
Tal Weiss

Reputation: 8999

I don't like repeating myself, but here is an answer that actually works: https://stackoverflow.com/a/31000713/78234
From the answer: Do not disable or weaken Pylint functionality by adding ignores or generated-members.
Use an actively developed Pylint plugin that understands Django.
This Pylint plugin for Django works quite well:

pip install pylint-django

and when running pylint add the following flag to the command:

--load-plugins pylint_django

Detailed blog post here.

Upvotes: 7

Xie Yanbo
Xie Yanbo

Reputation: 431

if you do not care some pylint's warnings, like unexistent member(E1101) and too many public methods(R0904), you can easily close it with:

pylint --disable=E1101,R0904

if you are interested with few checkers only, you can run pylint like this:

pylint --enable=basic,variables,classes,design,imports,newstyle,exceptions,format,miscellaneous,metrics,similarities

Upvotes: 5

alicederyn
alicederyn

Reputation: 13247

Easiest, provided your problematic code is not out of your control (e.g. autogenerated), is to disable the complaints in the areas you know they're spurious. Copying an example straight out of the message that first introduced this solution:

1  class foo:
2    # pylint: disable=W1234
3    def bar(self):
4      # pylint: disable=W4321
5      pass
6    def gnurz(self):
7      pass

Upvotes: 7

Related Questions