[Python-projects] Pylint not identifying types correctly

Sylvain Thénault sylvain.thenault at logilab.fr
Wed Apr 15 09:50:52 CEST 2009

On 14 avril 16:21, Marcelo de Sena Lacerda wrote:
> Hi, I'm new to the list and I'm having a problem with pylint. It is not
> identifying types correctly in the following code:
> org = Organization.get_by_key_name('LOL')
> str = org.key().name()
> The get_by_key_name method always returns a Organization instance that have
> a key() method.

huum, get_by_key_name... You're using appengine right ?
> Pylint however says that get_by_key_name returns a list, that does not have
> a key method.

Don't forget pylint is a *static* code analyser. You know things pylint won't ever be able to understand.
In that case pylint is probably infering that in some cases, get_by_key_name *may* return a list. 
But it has no idea about what other things may be returned.
> How do I solve this?

There are some tickets in our tracker about how to help pylint in some cases where static inference is not enough.
But this is an important development effort and we (logilab) have no resource to spend on it for now.
The thing you can do know is to explicitly disable messages on lines or blocks where you don't want them. 
Or tweak options to tell that 'key' is a dynamic attribute and so no warning should be issued.
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Debian, Méth. Agiles: http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
CubicWeb, the semantic web framework:    http://www.cubicweb.org

More information about the Python-Projects mailing list