Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 68a001d

Browse files
Issue #29460: _PyArg_NoKeywords(), _PyArg_NoStackKeywords() and
_PyArg_NoPositional() now are macros.
1 parent 6aee6fb commit 68a001d

4 files changed

Lines changed: 16 additions & 6 deletions

File tree

Include/modsupport.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,13 @@ PyAPI_FUNC(int) _PyArg_UnpackStack(
6262
PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs);
6363
PyAPI_FUNC(int) _PyArg_NoStackKeywords(const char *funcname, PyObject *kwnames);
6464
PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
65+
#define _PyArg_NoKeywords(funcname, kwargs) \
66+
((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs)))
67+
#define _PyArg_NoStackKeywords(funcname, kwnames) \
68+
((kwnames) == NULL || _PyArg_NoStackKeywords((funcname), (kwnames)))
69+
#define _PyArg_NoPositional(funcname, args) \
70+
((args) == NULL || _PyArg_NoPositional((funcname), (args)))
71+
6572
#endif
6673

6774
PyAPI_FUNC(PyObject *) Py_VaBuildValue(const char *, va_list);

Modules/_operator.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ itemgetter_call(itemgetterobject *ig, PyObject *args, PyObject *kw)
993993
PyObject *obj, *result;
994994
Py_ssize_t i, nitems=ig->nitems;
995995

996-
if (kw != NULL && !_PyArg_NoKeywords("itemgetter", kw))
996+
if (!_PyArg_NoKeywords("itemgetter", kw))
997997
return NULL;
998998
if (!PyArg_UnpackTuple(args, "itemgetter", 1, 1, &obj))
999999
return NULL;
@@ -1283,7 +1283,7 @@ attrgetter_call(attrgetterobject *ag, PyObject *args, PyObject *kw)
12831283
PyObject *obj, *result;
12841284
Py_ssize_t i, nattrs=ag->nattrs;
12851285

1286-
if (kw != NULL && !_PyArg_NoKeywords("attrgetter", kw))
1286+
if (!_PyArg_NoKeywords("attrgetter", kw))
12871287
return NULL;
12881288
if (!PyArg_UnpackTuple(args, "attrgetter", 1, 1, &obj))
12891289
return NULL;
@@ -1527,7 +1527,7 @@ methodcaller_call(methodcallerobject *mc, PyObject *args, PyObject *kw)
15271527
{
15281528
PyObject *method, *obj, *result;
15291529

1530-
if (kw != NULL && !_PyArg_NoKeywords("methodcaller", kw))
1530+
if (!_PyArg_NoKeywords("methodcaller", kw))
15311531
return NULL;
15321532
if (!PyArg_UnpackTuple(args, "methodcaller", 1, 1, &obj))
15331533
return NULL;

Objects/setobject.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1084,8 +1084,7 @@ frozenset_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
10841084
{
10851085
PyObject *iterable = NULL, *result;
10861086

1087-
if (kwds != NULL && type == &PyFrozenSet_Type
1088-
&& !_PyArg_NoKeywords("frozenset()", kwds))
1087+
if (type == &PyFrozenSet_Type && !_PyArg_NoKeywords("frozenset()", kwds))
10891088
return NULL;
10901089

10911090
if (!PyArg_UnpackTuple(args, type->tp_name, 0, 1, &iterable))
@@ -2002,7 +2001,7 @@ set_init(PySetObject *self, PyObject *args, PyObject *kwds)
20022001
{
20032002
PyObject *iterable = NULL;
20042003

2005-
if (kwds != NULL && !_PyArg_NoKeywords("set()", kwds))
2004+
if (!_PyArg_NoKeywords("set()", kwds))
20062005
return -1;
20072006
if (!PyArg_UnpackTuple(args, Py_TYPE(self)->tp_name, 0, 1, &iterable))
20082007
return -1;

Python/getargs.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2446,6 +2446,10 @@ _PyArg_UnpackStack(PyObject **args, Py_ssize_t nargs, const char *name,
24462446
}
24472447

24482448

2449+
#undef _PyArg_NoKeywords
2450+
#undef _PyArg_NoStackKeywords
2451+
#undef _PyArg_NoPositional
2452+
24492453
/* For type constructors that don't take keyword args
24502454
*
24512455
* Sets a TypeError and returns 0 if the args/kwargs is

0 commit comments

Comments
 (0)