mirror of
https://github.com/python/cpython.git
synced 2025-09-18 22:50:26 +00:00
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
This commit is contained in:
parent
f3cb68f2e4
commit
0567786d26
10 changed files with 43 additions and 46 deletions
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue