Pylint false positive for unused argument

I am doing pylint code cleanup to be able to use it for validation before committing. I have many warnings about an unused argument when they are used. Here is an example causing a false positive.

def addSeven(foo): #Here I have a warning "Unused argument 'foo'" foo += [7] example = [3, 4, 5, 6] addSeven(example) print example 

I do not want to suppress this warning globally, because I would like to see times when the argument is not really used. Is there another option that manually adds a disabled comment in each case? Is this a known issue with pylint?

+7
python pylint
source share
3 answers

This is reasonable behavior from pylint; if the transferred object is immutable, then this statement is essentially not an operator. Only when it is changed does it seem wrong.

Unfortunately, if you do not want to disable the warning globally, you need to disable it for each instance.

+5
source share

You can disable it for any area by adding:

 def myfunc(a): # pylint: disable=W0612,W0613 

see https://pylint.readthedocs.io/en/latest/faq.html#is-it-possible-to-locally-disable-a-particular-message

+10
source share

pylint is usually a good indicator of bad style. Even when he gives a โ€œfalse positiveโ€, it is probably due to the fact that he is doing something against the convention. I am not an expert, but I would say that a function that has only a side effect is not optimal. Some people (like Robert Martin in Clean Code) say that all side effects are false.

I would recommend (again, I'm not an expert):

 def addSeven(foo): return foo + [7] example = [3, 4, 5, 6] example = addSeven(example) 

Arguments should only be input, and the output should be through the return value. As far as I know, inference arguments are bad practice.

+4
source share

All Articles