jendrikseipp / vulture

Find dead Python code

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Is it possible to ignore an unused argument without globally ignoring all unused variables with the same name?

sliedes opened this issue · comments

When working on a large code base, I'd sometimes want to ignore unused function arguments, but definitely not all unused variables over all the code base with the same name. I may be mistaken, but it seems like the current whitelist approach is an all-or-nothing for this.

Often of course unused arguments can be renamed to e.g. start with an underscore to silence vulture, but not always. The function may be called with a keyword argument of that name, and still not using it is intentional.

One special case that I run often into is with the py.test framework, which is somewhat curious in that you depend on test fixtures by having the name of the fixture as a parameter:

@pytest.fixture
def somefixturename(): ...

def test_something(somefixturename): ...

and the parameter name defines which fixture gets invoked, thus it cannot be changed.

I took a quick glance at some other issues, and see that there is a focus on a whitelists of names as opposed to individually marking cases as intentionally unused. May I ask if this is because supporting individual markers is hard or because of some philosophy considering a global whitelist better?

Maybe I misunderstand and the whitelists are more powerful than I think. Nevertheless with my current understanding I'd personally much rather have those markings next to the code they apply to, also documenting to the reader that this is intentionally unused and alerting to the presence of an unused variable, than in a centralized registry.

Did I just miss something and there is an easy way to mark a variable as intentionally unused with the whitelist?

Your assessment is correct: whitelists are an all-or-nothing approach. Their main advantage is that they don't need to touch the real code. For marking parameters as unused, I recommend using the del unused_param idiom.