-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[feature request] New warning: too many positional arguments #9099
Comments
+1 |
As for specification would this proposed checker be for emitting a message where a function or class is called? (as opposed to |
As I'm hearing the request, it's just on the definition (and that's what I would suggest, too). |
Yeah, I intended this to be on the definition, just like the too-many-arguments warning (but excluding keyword-only arguments from the count and with a separate maximum) |
I think the idea behind Would the new checker raise for this situation (where the function call has explicitly passed the names of the parameters)? def tomato(one, two, three, four, five, six):
...
tomato(one=1, two=2, three=3, four=4, five=5, six=6) Perhaps if it were to raise for positional-only, then raising at definition time is ok: def tomato(one, two, three, four, five, six, /):
...
tomato(1, 2, 3, 4, 5, 6) |
Yeah; the idea was that the new checker would raise for: def tomato(one, two, three, four, five, six):
... and also raise for: def tomato(one, two, three, four, five, six, /):
... It would be OK with def tomato(one, two, *, three, four, five, six):
... and OK with def tomato(*, one, two, three, four, five, six):
... In any case, I was thinking of definition time; the design of the function encourages calls with a confusing undifferentiated argument list, regardless of whether or not it's called that way (or called at all). Call time would be more of a variant of #385, function actually being called with a confusing undifferentiated argument list, which is not what I was thinking of here... |
see: - pylint-dev/pylint#8667 (cause of the problem) - pylint-dev/pylint#9099 (potential solution)
I think #8667 was a mistake. “too many total arguments” could be a separate rule, but it’s much less useful than restricting the number of positional arguments. |
I'm happy that 8667 sparked the conversation and that ambiguity will be removed with the introduction of the new checker. |
Unfortunately, IMHO, significantly limiting number of keyword-only arguments only encourages bad practices, like:
There are other checks in pylint that discourage too complicated code, like too-many-branches and too-many-locals etc. which should be enough. With no obvious refactoring path for reasonable number of positional-only arguments, the change in #8667 made a useful check into a forced bunch of |
far too late to go with your suggestion of reverting this, but a new code for it has been reserved: https://pylint.pycqa.org/en/latest/user_guide/messages/refactor/too-many-positional.html you could either implement it here or switch to / add Ruff to your project |
Pylint 3.3.0 includes a new warning: too-many-positional-arguments [1]. We already ignore a similar too-many-arguments warning in several places since "fixing" it is backward-incompatible. 1. pylint-dev/pylint#9099
Pylint 3.3.0 includes a new warning: too-many-positional-arguments [1]. We already ignore a similar too-many-arguments warning in several places since "fixing" it is backward-incompatible. 1. pylint-dev/pylint#9099
Pylint 3.3.0 includes a new warning: too-many-positional-arguments [1]. We already ignore a similar too-many-arguments warning in several places since "fixing" it is backward-incompatible. 1. pylint-dev/pylint#9099
Current problem
With R0913 too-many-arguments now including keyword arguments (#8667), the reasonable setting for
max-args
is now larger, since it's not really a problem to have a dozen keyword-only arguments.However, having a dozen positional arguments remains a poor design.
Desired solution
A new warning for too many positional arguments, with a separately configurable maximum. This would warn when there are more than a very small number of positional arguments (including positional-only arguments).
This would be in addition to the existing too-many-arguments warning.
Additional context
This has been previously suggested in comments on #8667
The text was updated successfully, but these errors were encountered: