aisbaa
aisbaa

Reputation: 10643

pylint reports _ as not callable

Problem

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"))

Answer

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

Answers (4)

Radostin Stoyanov
Radostin Stoyanov

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

Tha&#237;s Vergani
Tha&#237;s Vergani

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

max
max

Reputation: 30013

pylint --additional-builtins=_ ... will get the job done in most scenarios.

Upvotes: 1

sthenault
sthenault

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

Related Questions