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
wrong error messages when too many kwargs are received #75412
Comments
Some functions produce wrong error messages in case they receive too many
keyword arguments:
- in Objects/exceptions.c - ImportError_init:
>>> ImportError(1, 2, 3, 4, a=5, b=6, c=7)
TypeError: ImportError() takes at most 2 arguments (3 given)
- in Python/bltinmodule.c - min_max:
>>> min(1, 2, 3, 4, a=5, b=6, c=7)
TypeError: function takes at most 2 arguments (3 given)
>>> max(1, 2, 3, 4, a=5, b=6, c=7)
TypeError: function takes at most 2 arguments (3 given)
- in Modules/itertoolsmodule.c - product_new:
>>> itertools.product(0, a=1, b=2, c=3, d=4, e=5, f=6)
TypeError: product() takes at most 1 argument (6 given)
- in Python/bltinmodule.c - builtin_print:
>>> print(0, a=1, b=2, c=3, d=4, e=5, f=6)
TypeError: print() takes at most 4 arguments (6 given) ISTM that changing these error messages to refer to 'keyword arguments' instead To do that, I changed two 'takes at most' PyErr_Format calls in Python/getargs.c. what do you think? |
In all of these cases PyArg_ParseTupleAndKeywords() is used in uncommon way. These functions accept variable number of positional-only arguments, and PyArg_ParseTupleAndKeywords() is called with empty args tuple for parsing keyword arguments only. The patch uses a trick for detecting this case and generating more appropriate error message. Correct error message is generated in a normal case too. LGTM. But it may be worth to add a short comment about the necessary of this special case. And please add tests for error messages in all of these functions. test_call looks appropriate place for them. |
Could you please make a PR from your patch Oren? |
I already wrote a patch, but I thought it would be better to wait until |
Thank you Oren for your contribution. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: