Search code examples
pythonpylint

pylint false positive for unused argument


I'm in the process of cleaning up code with pylint in order to be able to use it for pre-commit validation. I have a lot of "unused-argument" warning when in fact they are used. Here is an example triggering 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 wish to suppress globally this warning because i would like to see the times when an argument is really unused. Is there an other option that manually adding a disable comment in each occurence? Is it a known problem with pylint?


Solution

  • This is reasonable behavior from pylint; if the object passed is immutable then the statement given is essentially a no-op. Only when is mutable does it seem incorrect.

    Unfortunately if you don't want to globally disable the warning then you will need to disable it per instance.