summaryrefslogtreecommitdiff
path: root/Python/ceval.c
diff options
context:
space:
mode:
authorJeroen Demeyer <J.Demeyer@UGent.be>2019-08-16 12:41:27 +0200
committerMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-08-16 03:41:27 -0700
commit0567786d26348aa7eaf0ab1b5d038fdabe409d92 (patch)
treefe7c90392253850b8a3111b3177188a8f255dc79 /Python/ceval.c
parentf3cb68f2e4c3e0c405460f9bb881f5c1db70f535 (diff)
downloadcpython-git-0567786d26348aa7eaf0ab1b5d038fdabe409d92.tar.gz
bpo-37540: vectorcall: keyword names must be strings (GH-14682)
The fact that keyword names are strings is now part of the vectorcall and `METH_FASTCALL` protocols. The biggest concrete change is that `_PyStack_UnpackDict` now checks that and raises `TypeError` if not. CC @markshannon @vstinner https://bugs.python.org/issue37540
Diffstat (limited to 'Python/ceval.c')
-rw-r--r--Python/ceval.c24
1 files changed, 9 insertions, 15 deletions
diff --git a/Python/ceval.c b/Python/ceval.c
index 7c7359166d..ee03350031 100644
--- a/Python/ceval.c
+++ b/Python/ceval.c
@@ -3504,7 +3504,9 @@ main_loop:
PyObject **sp, *res, *names;
names = POP();
- assert(PyTuple_CheckExact(names) && PyTuple_GET_SIZE(names) <= oparg);
+ assert(PyTuple_Check(names));
+ assert(PyTuple_GET_SIZE(names) <= oparg);
+ /* We assume without checking that names contains only strings */
sp = stack_pointer;
res = call_function(tstate, &sp, oparg, names);
stack_pointer = sp;
@@ -5372,20 +5374,12 @@ format_kwargs_error(PyThreadState *tstate, PyObject *func, PyObject *kwargs)
_PyErr_Fetch(tstate, &exc, &val, &tb);
if (val && PyTuple_Check(val) && PyTuple_GET_SIZE(val) == 1) {
PyObject *key = PyTuple_GET_ITEM(val, 0);
- if (!PyUnicode_Check(key)) {
- _PyErr_Format(tstate, PyExc_TypeError,
- "%.200s%.200s keywords must be strings",
- PyEval_GetFuncName(func),
- PyEval_GetFuncDesc(func));
- }
- else {
- _PyErr_Format(tstate, PyExc_TypeError,
- "%.200s%.200s got multiple "
- "values for keyword argument '%U'",
- PyEval_GetFuncName(func),
- PyEval_GetFuncDesc(func),
- key);
- }
+ _PyErr_Format(tstate, PyExc_TypeError,
+ "%.200s%.200s got multiple "
+ "values for keyword argument '%S'",
+ PyEval_GetFuncName(func),
+ PyEval_GetFuncDesc(func),
+ key);
Py_XDECREF(exc);
Py_XDECREF(val);
Py_XDECREF(tb);