-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ANN001 for unused function argument #14663
Comments
Thanks for opening this issue. This is an interesting question and we may have to consider this in a more complete example. E.g is I agree that the type annotation seems rather useless for the |
Thanks for looking into this. I'm also not completely sure, but here is some context: I ran into this while writing a callback for a click option like this (snippet from the click documentation): def print_version(ctx, param, value):
if not value or ctx.resilient_parsing:
return
click.echo('Version 1.0')
ctx.exit()
@click.command()
@click.option('--version', is_flag=True, callback=print_version,
expose_value=False, is_eager=True)
def hello():
click.echo('Hello World!') Note that click calls the callback with positional parameters, so it doesn't care about the names. In my use case I only need the def callback(ctx: click.Context, param: click.Parameter, value: str): # raises ARG001
do_something_with(value)
def callback(_ctx, _param, value: str): # raises ANN001
do_something_with(value)
def callback(_ctx: click.Context, _param: click.Parameter, value: str): # works, but... hmmm
do_something_with(value) Pyright has a |
Hello I have the same issue, specially in methods that override parent methods, usually some arguments are unused in subclasses but they need to keep the same signature so I use single underscore prefix to mark as unused, but ANN001 keeps kiking my ass 😅 |
Oh, I just realized that [tool.ruff.lint.flake8-annotations]
suppress-dummy-args = true I think that should solve both your use cases. |
Huh, this works as described and does indeed solve my issue. Since I somehow overlooked this despite studying the documentation (I swear!), would it make sense to mention this setting in the description of the affected rules (just like Other than that, this can be closed from my side. Thanks! |
That's a good call out. Let me add it real quick. |
Given the setup
and the function
ruff (version 0.8.0) does not raise
ARG001
since the argument name_unused
matches thedummy-variable-rgx
pattern.It does, however, raise
ANN001
even though a type annotation for an unused argument doesn't make a lot of sense.Shouldn't the check for
ANN001
also take thedummy-variable-rgx
pattern into account?The text was updated successfully, but these errors were encountered: