diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2017-01-17 00:40:01 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2017-01-17 00:40:01 (GMT) |
commit | 29d39cc8f50f314a62226d69ac014cbd0bd66792 (patch) | |
tree | 62bc43421910c3a85c6599d9077b9e4b1e571bfd /Python | |
parent | 6518a93cb1dd9ff971a7455eb1622a4c89da4bb4 (diff) | |
download | cpython-29d39cc8f50f314a62226d69ac014cbd0bd66792.zip cpython-29d39cc8f50f314a62226d69ac014cbd0bd66792.tar.gz cpython-29d39cc8f50f314a62226d69ac014cbd0bd66792.tar.bz2 |
Add _PyArg_NoStackKeywords() helper function
Issue #29286. Similar to _PyArg_NoKeywords(), but expects a tuple of keyword
names, instead of a dict.
Diffstat (limited to 'Python')
-rw-r--r-- | Python/getargs.c | 25 |
1 files changed, 21 insertions, 4 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 35500d7..e3611d8 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2429,16 +2429,33 @@ PyArg_UnpackTuple(PyObject *args, const char *name, Py_ssize_t min, Py_ssize_t m * not empty, returns 1 otherwise */ int -_PyArg_NoKeywords(const char *funcname, PyObject *kw) +_PyArg_NoKeywords(const char *funcname, PyObject *kwargs) { - if (kw == NULL) + if (kwargs == NULL) return 1; - if (!PyDict_CheckExact(kw)) { + if (!PyDict_CheckExact(kwargs)) { PyErr_BadInternalCall(); return 0; } - if (PyDict_GET_SIZE(kw) == 0) + if (PyDict_GET_SIZE(kwargs) == 0) { return 1; + } + + PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments", + funcname); + return 0; +} + + +int +_PyArg_NoStackKeywords(const char *funcname, PyObject *kwnames) +{ + if (kwnames == NULL) + return 1; + assert(PyTuple_CheckExact(kwnames)); + if (PyTuple_GET_SIZE(kwnames) == 0) { + return 1; + } PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments", funcname); |