[Python-projects] false positive: undefined variable for method references as decorator args

Sylvain Thénault sylvain.thenault at logilab.fr
Tue Mar 27 12:37:31 CEST 2007


On Tuesday 27 March à 12:25, Thomas Moschny wrote:
> Hi!
> 
> consider this (stripped down and simplified) code sniplet:
> 
> def decorate(get_name):
>     def f(func):
>         def new_method(self, *args):
>             print "calling", func.__name__, "in", get_name(self)
>             func(self, *args)
>         return new_method
>     return f
> 
> class Foo(object):
> 
>     def __init__(self, name):
>         self.name = name
>     
>     def get_name(self):
>         return self.name
> 
>     @decorate(get_name) # <-------- HERE
>     def foo(self, arg):
>         print "foo:", arg
>     
> Foo("bar").foo("baz")
> 
> </snip>
> 
> pylint 0.13.1 gives me an E0602 "Foo.foo: Undefined variable 'get_name'" in 
> the marked line, which imho is a false positive, as this code runs fine with 
> python 2.4.4, and I see no reason why one should not be able to pass a 
> reference to another method this way.

which astng version are you using? This bug should have been fixed by
the latest version.
-- 
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