-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
reportUnusedFunctionParameter? #2046
Comments
I am highly skeptical that such an option would be useful in anything but the most simple and contrived pieces of Python code. There are just way too many cases where parameters must be present but are legitimately unused. This is true for subclass method overrides, parameters for test frameworks, and callback functions. |
I think the rule that would be enough to cover most cases is overrides don't count and arguments starting with an _ can be unused. Most callbacks I encounter don't care about the names of the function arguments. I'm still -1 as I think this is outside the scope of a type checker and in scope for a linter. pylint supports unused argument warning and type checker does not need to cover all potential style issues a linter should cover. |
As a functional programmer,
For code that I write, this feature would be useful. I realize that functional programmers are not typical, but we're also not unique. Again, I'm not asking that this rule be enforced by default - just that I have the option to enable it.
That's a fair point.
Thanks for the tip. I'll check it out :)
agreed :) |
Thanks for the additional details. We generally add new diagnostic checks only when we've received signal from enough users that it's going to be generally useful. I'm going to close this one for now, but if it receives enough upvotes or additional comments, we'll consider reopening it in the future. |
This is a problem when you rely on def wrapper_function(
lots: str,
of: str,
args: str,
...
) -> SomeType:
"""
A function wrapping another function
"""
stored_kwargs = locals()
# Do stuff
new_arg = 1
new_kwarg = 2
return wrapped_function(new_arg, **{**stored_kwargs, "foo": new_kwarg}) We use this pattern a lot and end up with literally hundreds of pyright hints in different repos. |
Is your feature request related to a problem? Please describe.
I rely heavily on type checking for refactoring.
I recently extracted some hard-coded values into function parameters and plumbed the function parameter through the call chain.
But then I forgot to actually replace the hard-coded value with the function parameter.
This resulted in a run-time error (since the hard-coded value was no longer valid).
The type checker didn't help here, which was surprising to me.
This is just one example.
I know there are use-cases for not using function parameters, but when I write functions whos signatures I can control (which is nearly all of them), not using a function parameter is a bug.
Describe the solution you'd like
I'd like to have the option to enable
reportUnusedFunctionParameter
.Additional context
I notice comments in #1895 and #1118 like this:
Originally posted by @erictraut in #1118 (comment)
Since it's possible to provide hints, seems like it should also be possible to optionally emit warnings or errors, right?
The text was updated successfully, but these errors were encountered: