-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
bpo-37034: Display argument name on errors with keyword-only arguments with Argument Clinic #13593
bpo-37034: Display argument name on errors with keyword-only arguments with Argument Clinic #13593
Conversation
Is _PyArg_BadArgument() used with positional-only argument? If yes, your PR is wrong. The name of positional-only arguments must not be used. |
I tried to take care of this case in https://github.com/python/cpython/pull/13593/files#diff-5e15637e15d50f49f6cb1d7f69fcab4bR854. Did I miss something? If so, happy to start again :D |
I don't think that this line is correct. You should also use the parameter name for positional-or-keyword. I propose the following change on top of your PR:
I'm not even sure that my change is correct. Maybe is_positional_only() should be used to decide if the name must not be used. I removed repr() to let the compiler merge duplicated strings. If you care of '...' format, please add use 2 exclusive parameters in _PyArg_BadArgument(): one for argument position, one for positional-only arguments. |
By the way, that would be my preference: it's strange to store an integer as a bytes string ("2") rather than just an int (2). |
Thanks, I wasn't sure what to do here so I made a conservative choice but I agree this is better. In the implementation of |
If the parameter is a keyword-only or positional-or-keyword, IHMO we must display its name. it's helpful. |
Yes but for positional only parameters, the current message is
without indications about which parameter (when it is the first one), instead of the more useful
This could be confusing when there is multiple arguments, should I keep the first one or make it display the second one? |
is fine if the function accepts 0 or 1 argument.
is bad if the function accepts more than 1 argument. |
Hi Victor, thanks for your feedback. I updated the PR based on your comments, it should be better now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please re base
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. I just ask a minor change, add a comment :-)
@serhiy-storchaka: Would you mind to double check this change?
5df18f7
to
7118e43
Compare
Hi, I made the last changes and regenerated the clinic files. I tried to do a squashed merge but that made GitHub noisy-ing nearly everybody, sorry about that :/ |
Thanks @remilapeyre for the PR, and @serhiy-storchaka for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8. |
Sorry, @remilapeyre and @serhiy-storchaka, I could not cleanly backport this to |
…ts with Argument Clinic. (pythonGH-13593). (cherry picked from commit 4901fe2) Co-authored-by: Rémi Lapeyre <remi.lapeyre@henki.fr>
GH-15599 is a backport of this pull request to the 3.8 branch. |
…h Argument Clinic. (pythonGH-13593)
…h Argument Clinic. (pythonGH-13593)
…h Argument Clinic. (pythonGH-13593)
https://bugs.python.org/issue37034