Using Pylint with Django


I would very much like to integrate pylint into the build process for my python projects, but I have run into one show-stopper: One of the error types that I find extremely useful--:E1101: *%s %r has no %r member*--constantly reports errors when using common django fields, for example:

E1101:125:get_user_tags: Class 'Tag' has no 'objects' member

which is caused by this code:

def get_user_tags(username):
   Gets all the tags that username has used.

   Returns a query set.
   return Tag.objects.filter(  ## This line triggers the error.

# Here is the Tag class, models.Model is provided by Django:
class Tag(models.Model):
   Model for user-defined strings that help categorize Events on
   on a per-user basis.
   name = models.CharField(max_length=500, null=False, unique=True)

   def __unicode__(self):

How can I tune Pylint to properly take fields such as objects into account? (I've also looked into the Django source, and I have been unable to find the implementation of objects, so I suspect it is not "just" a class field. On the other hand, I'm fairly new to python, so I may very well have overlooked something.)

Edit: The only way I've found to tell pylint to not warn about these warnings is by blocking all errors of the type (E1101) which is not an acceptable solution, since that is (in my opinion) an extremely useful error. If there is another way, without augmenting the pylint source, please point me to specifics :)

See here for a summary of the problems I've had with pychecker and pyflakes -- they've proven to be far to unstable for general use. (In pychecker's case, the crashes originated in the pychecker code -- not source it was loading/invoking.)

10/8/2013 10:47:52 PM

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.

6/23/2015 11:25:22 AM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow