12

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.

Community
  • 1
  • 1
JivanAmara
  • 1,065
  • 2
  • 10
  • 20

3 Answers3

7

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.

Community
  • 1
  • 1
Tal Weiss
  • 8,889
  • 8
  • 54
  • 62
  • 1
    This should be the answer, tweaking pylint options and turning errors off, it is a bit of a blunt instrument as any option is applied globally – Niyojan Jan 23 '17 at 07:42
7

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
Alice Purcell
  • 12,622
  • 6
  • 51
  • 57
  • Thanks for the reply, and that would be great if they could be disabled once inside the class, but the error is reported every time the member is used and has to be disabled at every place it is used. Not really practical. – JivanAmara Aug 12 '10 at 01:55
5

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
Xie Yanbo
  • 430
  • 6
  • 16