diff options
author | Jeroen Demeyer <J.Demeyer@UGent.be> | 2019-08-16 10:41:27 (GMT) |
---|---|---|
committer | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-08-16 10:41:27 (GMT) |
commit | 0567786d26348aa7eaf0ab1b5d038fdabe409d92 (patch) | |
tree | fe7c90392253850b8a3111b3177188a8f255dc79 /Python/getargs.c | |
parent | f3cb68f2e4c3e0c405460f9bb881f5c1db70f535 (diff) | |
download | cpython-0567786d26348aa7eaf0ab1b5d038fdabe409d92.zip cpython-0567786d26348aa7eaf0ab1b5d038fdabe409d92.tar.gz cpython-0567786d26348aa7eaf0ab1b5d038fdabe409d92.tar.bz2 |
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/getargs.c')
-rw-r--r-- | Python/getargs.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 59f0fda..cdc16d4 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2043,11 +2043,7 @@ find_keyword(PyObject *kwnames, PyObject *const *kwstack, PyObject *key) if (kwname == key) { return kwstack[i]; } - if (!PyUnicode_Check(kwname)) { - /* ignore non-string keyword keys: - an error will be raised below */ - continue; - } + assert(PyUnicode_Check(kwname)); if (_PyUnicode_EQ(kwname, key)) { return kwstack[i]; } @@ -2275,16 +2271,11 @@ vgetargskeywordsfast_impl(PyObject *const *args, Py_ssize_t nargs, j++; } - if (!PyUnicode_Check(keyword)) { - PyErr_SetString(PyExc_TypeError, - "keywords must be strings"); - return cleanreturn(0, &freelist); - } match = PySequence_Contains(kwtuple, keyword); if (match <= 0) { if (!match) { PyErr_Format(PyExc_TypeError, - "'%U' is an invalid keyword " + "'%S' is an invalid keyword " "argument for %.200s%s", keyword, (parser->fname == NULL) ? "this function" : parser->fname, @@ -2505,16 +2496,11 @@ _PyArg_UnpackKeywords(PyObject *const *args, Py_ssize_t nargs, j++; } - if (!PyUnicode_Check(keyword)) { - PyErr_SetString(PyExc_TypeError, - "keywords must be strings"); - return NULL; - } match = PySequence_Contains(kwtuple, keyword); if (match <= 0) { if (!match) { PyErr_Format(PyExc_TypeError, - "'%U' is an invalid keyword " + "'%S' is an invalid keyword " "argument for %.200s%s", keyword, (parser->fname == NULL) ? "this function" : parser->fname, |