[Python-projects] pylint: unused local variables and their context
Pierre_Rouleau at ImpathNetworks.com
Pierre_Rouleau at ImpathNetworks.com
Thu Nov 30 18:06:31 CET 2006
Daniel Drake wrote:
>> Hi,
Hello,
>>
>> pylint is throwing up "unused variable" warnings for code such as:
>>
>> for x in range(0, MAX):
>> some_code()
>>
>> That is, a loop which declares a local variable 'x' where 'x' is not
>> actually used.
>>
>> pylint flags x as an unused local variable.
This warning does annoy me a little too, however, i'd like to see what other do
to avoid the warning.
In certain situations, the warning might just be what you need to remember to
use the loop index.
So removing the warning might not be the best solution afterall.
>>
>> Another example:
>>
>> x, y, z = self.getCoords()
>> self.checkxy(x, y)
>>
>> That is, a tuple is assigned from a function return tuple, but not all
>> members of the tuple are used.
Why not write::
x, y = self.getCoords()[:2]
self.checkxy(x, y)
>>
>> It would be nice if pylint could *not* flag these as unused variables:
>> loop counters, variables assigned as parts of a tuple assignment
>>
As far as I am concerned, I prefer to get a pylint warning for unused
variables in tuple assignment. I don't like leaving things hanging.
--
Pierre Rouleau
More information about the Python-Projects
mailing list