-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
gh-136327: Fix inconsistent TypeError messages regarding invalid values after * and ** #136395
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Errors when calling functions with invalid values after * and ** now do not | ||
include the function name. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3264,17 +3264,9 @@ int | |
_Py_Check_ArgsIterable(PyThreadState *tstate, PyObject *func, PyObject *args) | ||
{ | ||
if (Py_TYPE(args)->tp_iter == NULL && !PySequence_Check(args)) { | ||
/* _Py_Check_ArgsIterable() may be called with a live exception: | ||
* clear it to prevent calling _PyObject_FunctionStr() with an | ||
* exception set. */ | ||
_PyErr_Clear(tstate); | ||
PyObject *funcstr = _PyObject_FunctionStr(func); | ||
if (funcstr != NULL) { | ||
_PyErr_Format(tstate, PyExc_TypeError, | ||
"%U argument after * must be an iterable, not %.200s", | ||
funcstr, Py_TYPE(args)->tp_name); | ||
Py_DECREF(funcstr); | ||
} | ||
_PyErr_Format(tstate, PyExc_TypeError, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not to use %T formatter here? IIUC it is preferable now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nikita's suggestions on removing the function name entirely were motivated by the fact that getting this name is not fast and does not add much value (in fact, none at all). I've looked into the %T specification, and it seems to do x2 of work we just got rid of, so I doubt that that would be a positive change. Anyway, we're waiting on Mark's review on that, maybe he has another opinion |
||
"Value after * must be an iterable, not %.200s", | ||
Py_TYPE(args)->tp_name); | ||
return -1; | ||
} | ||
return 0; | ||
|
@@ -3290,15 +3282,10 @@ _PyEval_FormatKwargsError(PyThreadState *tstate, PyObject *func, PyObject *kwarg | |
* is not a mapping. | ||
*/ | ||
if (_PyErr_ExceptionMatches(tstate, PyExc_AttributeError)) { | ||
_PyErr_Clear(tstate); | ||
sobolevn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
PyObject *funcstr = _PyObject_FunctionStr(func); | ||
if (funcstr != NULL) { | ||
_PyErr_Format( | ||
tstate, PyExc_TypeError, | ||
"%U argument after ** must be a mapping, not %.200s", | ||
funcstr, Py_TYPE(kwargs)->tp_name); | ||
Py_DECREF(funcstr); | ||
} | ||
_PyErr_Format( | ||
tstate, PyExc_TypeError, | ||
"Value after ** must be a mapping, not %.200s", | ||
Py_TYPE(kwargs)->tp_name); | ||
} | ||
else if (_PyErr_ExceptionMatches(tstate, PyExc_KeyError)) { | ||
PyObject *exc = _PyErr_GetRaisedException(tstate); | ||
|
Uh oh!
There was an error while loading. Please reload this page.