diff --git a/Include/modsupport.h b/Include/modsupport.h index 7f4160e5bac..853860f4d27 100644 --- a/Include/modsupport.h +++ b/Include/modsupport.h @@ -62,6 +62,13 @@ PyAPI_FUNC(int) _PyArg_UnpackStack( 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); +#define _PyArg_NoKeywords(funcname, kwargs) \ + ((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs))) +#define _PyArg_NoStackKeywords(funcname, kwnames) \ + ((kwnames) == NULL || _PyArg_NoStackKeywords((funcname), (kwnames))) +#define _PyArg_NoPositional(funcname, args) \ + ((args) == NULL || _PyArg_NoPositional((funcname), (args))) + #endif PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list); diff --git a/Modules/_operator.c b/Modules/_operator.c index 9374b8e8a59..10d78745799 100644 --- a/Modules/_operator.c +++ b/Modules/_operator.c @@ -993,7 +993,7 @@ itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw) PyObject *obj, *result; Py_ssize_t i, nitems=ig->nitems; - if (kw != NULL && !_PyArg_NoKeywords("itemgetter", kw)) + if (!_PyArg_NoKeywords("itemgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj)) return NULL; @@ -1283,7 +1283,7 @@ attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw) PyObject *obj, *result; Py_ssize_t i, nattrs=ag->nattrs; - if (kw != NULL && !_PyArg_NoKeywords("attrgetter", kw)) + if (!_PyArg_NoKeywords("attrgetter", kw)) return NULL; if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj)) return NULL; @@ -1527,7 +1527,7 @@ methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw) { PyObject *method, *obj, *result; - if (kw != NULL && !_PyArg_NoKeywords("methodcaller", kw)) + if (!_PyArg_NoKeywords("methodcaller", kw)) return NULL; if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj)) return NULL; diff --git a/Objects/setobject.c b/Objects/setobject.c index 4f04f49efaa..2ccf183e3c7 100644 --- a/Objects/setobject.c +++ b/Objects/setobject.c @@ -1084,8 +1084,7 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds) { PyObject *iterable = NULL, *result; - if (kwds != NULL && type == &PyFrozenSet_Type - && !_PyArg_NoKeywords("frozenset()", kwds)) + if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds)) return NULL; if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable)) @@ -2002,7 +2001,7 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds) { PyObject *iterable = NULL; - if (kwds != NULL && !_PyArg_NoKeywords("set()", kwds)) + if (!_PyArg_NoKeywords("set()", kwds)) return -1; if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable)) return -1; diff --git a/Python/getargs.c b/Python/getargs.c index 952a662ecf5..8cb672d6abc 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -2446,6 +2446,10 @@ _PyArg_UnpackStack(PyObject **args, Py_ssize_t nargs, const char *name, } +#undef _PyArg_NoKeywords +#undef _PyArg_NoStackKeywords +#undef _PyArg_NoPositional + /* For type constructors that don't take keyword args * * Sets a TypeError and returns 0 if the args/kwargs is