Reputation: 10643
I have imported ugettext_lazy as _ but pylint complains that _ is not callable. Is there a way to ignore this error message?
from django.utils.translation import ugettext_lazy as _
...
class A(models.Model):
name = models.CharField(max_length=255, verbose_name=_("Name"))
It seems I've found half of answer. There is a way to ignore certain messages.
[MESSAGES CONTROL]
disable=E1102[,<msg id>]+
to get list of messages and ids:
shell> pylint --list-msgs
Why its only half of solution? Well no it does not report situations like this:
asdf = 5
asdf()
Maybe there is a way to specify error cause, but thats for another day :|.
Thank you all.
Upvotes: 4
Views: 7545
Reputation: 336
Add the following in your pylintrc file
[VARIABLES]
additional-builtins=_
This will add the underscore symbol to a list of additional names supposed to be defined in builtins and pylint will not complain about it.
Upvotes: 3
Reputation: 5
_ refers to the last outputed value
so, that could probably be the error cause
>>> 1 + 1
2
>>> print _
2
>>> _("foo")
TypeError: 'int' object is not callable
Upvotes: -2
Reputation: 30013
pylint --additional-builtins=_ ...
will get the job done in most scenarios.
Upvotes: 1
Reputation: 15125
Disabling the message in your pylintrc file to avoid a false-positive is definitly not a solution as it will totally deactivate this check.
Taking a look at django's source code, it seems like pylint doesn't like the lazy()
stuff.
Django people should probably read http://www.logilab.org/blogentry/78354 and start a django specific plugin, which could easily fix such problems.
Upvotes: 4