[Freeipa-devel] pylint: remove unused variables

Martin Basti mbasti at redhat.com
Fri Sep 23 12:11:03 UTC 2016



On 23.09.2016 14:12, Jan Cholasta wrote:
> On 23.9.2016 13:23, Standa Laznicka wrote:
>> On 09/23/2016 07:28 AM, Jan Cholasta wrote:
>>> On 22.9.2016 16:39, Martin Basti wrote:
>>>> Hello all,
>>>>
>>>> In 4.5, I would like to remove all unused variables from code and 
>>>> enable
>>>> pylint check. Due to big amount of unused variables in the code this
>>>> will be longterm effort.
>>>>
>>>> Why this?:
>>>>
>>>> * better code readability
>>>>
>>>> * removing dead code
>>>>
>>>> * unused variable may uncover potential bug
>>>>
>>>>
>>>> It is clear what to do with unused assignments, but I need an 
>>>> agreement
>>>> what to do with unpacking or iteration with unused variables
>>>>
>>>>
>>>> For example:
>>>>
>>>> for name, surname, gender in (('Martin', 'Basti', 'M'), ):
>>>>
>>>> name, surname, gender = user['mbasti']
>>>>
>>>> Where 'surname' is unused
>>>>
>>>>
>>>> Pylint will detect surname as unused variable and we have to agree 
>>>> on a
>>>> way how to tell pylint that this variable is unused on purpose:
>>>>
>>>>
>>>> 1)
>>>>
>>>> (
>>>>
>>>>    name,
>>>>
>>>>    surname,  # pylint: disable=unused-variable
>>>>
>>>>    gender
>>>>
>>>> ) = user['mbasti']
>>>>
>>>>
>>>> I dont like this approach
>>>
>>> +1
>>>
>>>>
>>>>
>>>> 2)
>>>>
>>>> Use defined keyword: 'dummy' is default in pylint, we can set our own,
>>>> like ignored, unused
>>>>
>>>> name, dummy, gender = user['mbasti']
>>>
>>> -1, not visible enough.
>>>
>>>>
>>>>
>>>> 3)
>>>>
>>>> use a prefix for unused variables: '_' or 'ignore_'
>>>>
>>>> name, _surname, gender = user['mbasti']
>>>
>>> This. We have already been using it in new code for quite some time,
>>> and it's common in other Python projects too. Don't reinvent the wheel.
>>>
>>>>
>>>>
>>>> 4)
>>>>
>>>> we can combine all :)
>>>>
>>>>
>>>> For me the best is to have prefix '_' and 'dummy' keyword
>>>
>>> Use '_dummy', it's both :-)
>>>
>> +1. I would rather use _meh as it's easier to type but perhaps not that
>> self-explanatory and not established at all, so _dummy is just fine :)
>
> What I'm actually suggesting is that any local variable with "_" 
> prefix should be considered unused, so _meh would be fine as well.
>

+1 regexp '_.+' works for me




More information about the Freeipa-devel mailing list