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

Pierre_Rouleau at ImpathNetworks.com Pierre_Rouleau at ImpathNetworks.com
Thu Nov 30 21:51:48 CET 2006


Marteen wrote:

>> Pierre Rouleau wrote on 2006-11-30 06:06:31 PM:
>>
>> > 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.
>>
>> Like Duncan, we use a naming convention:
>>
>> The code looks like this:
>>
>>         for x_ in range(0, MAX):
>>                 some_code()
>>
>>         x, y, z_ = self.getCoords()
>>
>> And in pylintrc we have:
>>
>> dummy-variables-rgx=_|([^_]+_)|dummy
>>
>> Now that I see it again, I noticed that it can be simplified to:
>> ([^_]*_)|dummy


OK, that's a good idea.  However, I would use

        dummy-variables-rgx=dummy|.+_$

to ensure that it accepts only variables that ends with underscores,
regardless of the presence of underscores inside the name. This way,
dummy variables include:

        a_x_
        x_

but not:

        a_x

as your expression allows.

One disadvantage though, is that we are using both pychecker and
pylint, and pychecker will complain. I should look to see if I can
instruct pychecker to allow the same dummy variable though.

--

Pierre R.




More information about the Python-Projects mailing list