[Python-projects] PyLint: Type inference fails on classmethod

Sylvain Thénault sylvain.thenault at logilab.fr
Thu Feb 8 23:12:41 CET 2007


On Tuesday 06 February à 19:40, Maarten ter Huurne wrote:
> 
> Hi,

Hey Maarten,
 
> When I run PyLint on this program:
> ===
> class Super(object):
>         @classmethod
>         def instance(cls):
>                 return cls()
> 
> class Sub(Super):
>         def method(self):
>                 print 'method called'
> 
> Sub.instance().method()
> ===
> It prints:
> ===
> E1101: 10: Instance of 'Super' has no 'method' member
> ===
> 
> The return type of "Sub.instance()" is "Sub", not "Super", so the method call
> is valid, as you can see when you run this program.
> 
> So it seems that ASTNG infers the wrong type: "cls" is the class on which the
> class method is called, which is not necessarily the class in which it is
> defined.

huum, remember astng inference is dumb ;) I guess it should at least see
that it may be wrong and return a YES object as well so that pylint
don't issue a false positive.

I'll add this to the tracker tomorrow, thanks for the report.

-- 
Sylvain Thénault                               LOGILAB, Paris (France)
Formations Python, Zope, Plone, Debian:  http://www.logilab.fr/formations
Développement logiciel sur mesure:       http://www.logilab.fr/services
Python et calcul scientifique:           http://www.logilab.fr/science



More information about the Python-Projects mailing list