[Python-projects] pylint false positive: Unused argument/variable on "-="

Sylvain Thénault sylvain.thenault at logilab.fr
Thu Mar 26 08:32:03 CET 2009


Le Thursday 26 March 2009 01:20:57 skip at pobox.com, vous avez écrit :
>     Maarten> Another false positive. Again, I think it is new, but not 100%
>     Maarten> sure.
>
>     Maarten> ===
>     Maarten> def exclude(setA, setB):
>     Maarten>    setA -= setB
>     Maarten> ===
>     Maarten> W0613:  1:exclude: Unused argument 'setA'
>
>     Maarten> Or a variant with a local variable instead of an argument:
>     Maarten> ===
>     Maarten> def exclude(func, setB):
>     Maarten>    setA = func()
>     Maarten>    setA -= setB
>     Maarten> ===
>     Maarten> W0612:  2:exclude: Unused variable 'setA'
>
>     Maarten> It seems that the left side of "-=" is not considered a use of
>     Maarten> the argument/variable.
>
> I think pylint is doing the correct thing here.  You set setA and change
> its value but never use it to affect the state of the system (other than
> setA's value itself).

I'm divided between your point and Maarteen's one. W0612 should clearly be 
issued on the second example, imo. In the first case (eg, name coming from 
argument), I'm not sure. Though I'm tented to let it since it may flag 
undesired code, and you still have the ability to disable it locally. But if 
there is a consensus to not issue it in case of aug-assigned arguments, I'll 
change that.

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