From 29d39cc8f50f314a62226d69ac014cbd0bd66792 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Jan 2017 01:40:01 +0100 Subject: Add _PyArg_NoStackKeywords() helper function Issue #29286. Similar to _PyArg_NoKeywords(), but expects a tuple of keyword names, instead of a dict. --- Include/modsupport.h | 3 ++- Python/getargs.c | 25 +++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Include/modsupport.h b/Include/modsupport.h index 5c21f98..e6713e2 100644 --- a/Include/modsupport.h +++ b/Include/modsupport.h @@ -48,7 +48,8 @@ PyAPI_FUNC(PyObject *) Py_BuildValue(const char *, ...); PyAPI_FUNC(PyObject *) _Py_BuildValue_SizeT(const char *, ...); #endif #ifndef Py_LIMITED_API -PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kw); +PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs); +PyAPI_FUNC(int) _PyArg_NoStackKeywords(const char *funcname, PyObject *kwnames); PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args); PyAPI_FUNC(int) PyArg_VaParse(PyObject *, const char *, va_list); 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); -- cgit v0.12