views:

163

answers:

3

Hi all, 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.

+1  A: 

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
chrispy
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
A: 

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
The OP mentioned he doesn't want to suppress these errors globally.
chrispy
A: 

Ok, this is a serious hack but I got pylint and django working together. Since the errors give a text description containing the name of the class they refer to, I turned off the reports in the pylintrc file and wrote a bash script to pipe the output of pylint into a series of grep -v 'text description' commands. The output is the name of the files checked, followed by problems not removed by the script (if there are any).

My only disappointment with this approach is losing the pylint score, as the approach doesn't work if pylint is also spitting out the reports.

JivanAmara