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

Maarten ter Huurne maarten at treewalker.org
Thu Mar 26 01:37:16 CET 2009


On Thursday 26 March 2009, skip at pobox.com wrote:
>     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).

The "setA" variable itself is indeed unused. But the value of the object 
that "setA" refers to is most likely used somewhere outside this function. 
For example:

a = set(range(10))
exclude(a, set(range(5, 15)))
print a

Bye,
		Maarten



More information about the Python-Projects mailing list