nhoad / flake8-unused-arguments

Flake8 plugin to warn against unused arguments in functions
MIT License
31 stars 8 forks source link

Fix ignores first unused argument in classmethods #7

Closed SebDieBln closed 3 years ago

SebDieBln commented 3 years ago

This PR fixes #6.

nhoad commented 3 years ago

Hi! Apologies for the delay!! Just to make sure I understand your fix - this is ensuring we can iterate over arguments more than once by converting it from a generator into a list, yes?

SebDieBln commented 3 years ago

Hi @nhoad

thanks for getting back to me.

This PR is not about generator vs. list but about the meaning of the number that is associated with an unused argument (variable i in line 73).

We need that number to be the index within the original argument list. (Because we want to ignore an unused argument if it is the first argument in the original argument list.)

Before this PR however that number is an index within the list of unused arguments. This has the effect that instead of only ignoring an unused argument if it is the first argument we always ignore the first unused argument, no matter what its position is. (of course this all applies only to "classmethod"s).

@classmethod
def someMethod(cls, foo):
    # Note that 'foo' is not used by this function.
    # It is not the *first* argument, but it is the *first unused* argument.
    print(cls)

Since foo is the first unused argument it is currently ignored, even though it is not the first argument.

nhoad commented 3 years ago

Awesome, that was a great explanation! Thank you Sebastian!!

nhoad commented 3 years ago

I've pushed v0.0.7 to pypi now. Thanks again!