[Python-projects] pylint: unused local variables and their context

Daniel Drake ddrake at brontes3d.com
Thu Nov 30 17:31:47 CET 2006


Hi,

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.

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.

It would be nice if pylint could *not* flag these as unused variables:
loop counters, variables assigned as parts of a tuple assignment

I looked at the code but it appears that the actual context in which
these local variables are used is not known when the warning is raised.

Does anyone have any suggestions for fixing this properly inside pylint?
(I know that we could simply name those variables in a way that pylint
ignores them, but I'd much prefer a transparent solution)

Thanks!
-- 
Daniel Drake
Brontes Technologies, A 3M Company



More information about the Python-Projects mailing list