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.
tagownership__users__username__exact=username).distinct()
# 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):
return self.name
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.)
If you use Visual Studio Code do this:
pip install pylint-django
And add to VSC config:
Try running pylint with
If that works, add all the other Django classes - possibly using a script, in say, python :P
The documentation for
--ignore-classes
is:I should add this is not a particular elegant solution in my view, but it should work.
For
neovim & vim8
usew0rp's ale
plugin. If you have installed everything correctly includingw0rp's ale
,pylint
&pylint-django
. In yourvimrc
add the following line & have fun developing web apps using django. Thanks.Do not disable or weaken Pylint functionality by adding
ignores
orgenerated-members
.Use an actively developed Pylint plugin that understands Django.
This Pylint plugin for Django works quite well:
and when running pylint add the following flag to the command:
Detailed blog post here.
django-lint is a nice tool which wraps pylint with django specific settings : http://chris-lamb.co.uk/projects/django-lint/
github project: https://github.com/lamby/django-lint
I resigned from using pylint/pychecker in favor of using pyflakes with Django code - it just tries to import module and reports any problem it finds, like unused imports or uninitialized local names.