mirror of https://github.com/python/cpython
bpo-37207: Add _PyArg_NoKwnames() helper function (GH-18980)
This commit is contained in:
parent
c98f87fc33
commit
87ec86c425
|
@ -60,9 +60,12 @@ PyAPI_FUNC(int) _PyArg_UnpackStack(
|
||||||
...);
|
...);
|
||||||
|
|
||||||
PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs);
|
PyAPI_FUNC(int) _PyArg_NoKeywords(const char *funcname, PyObject *kwargs);
|
||||||
|
PyAPI_FUNC(int) _PyArg_NoKwnames(const char *funcname, PyObject *kwnames);
|
||||||
PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
|
PyAPI_FUNC(int) _PyArg_NoPositional(const char *funcname, PyObject *args);
|
||||||
#define _PyArg_NoKeywords(funcname, kwargs) \
|
#define _PyArg_NoKeywords(funcname, kwargs) \
|
||||||
((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs)))
|
((kwargs) == NULL || _PyArg_NoKeywords((funcname), (kwargs)))
|
||||||
|
#define _PyArg_NoKwnames(funcname, kwnames) \
|
||||||
|
((kwnames) == NULL || _PyArg_NoKwnames((funcname), (kwnames)))
|
||||||
#define _PyArg_NoPositional(funcname, args) \
|
#define _PyArg_NoPositional(funcname, args) \
|
||||||
((args) == NULL || _PyArg_NoPositional((funcname), (args)))
|
((args) == NULL || _PyArg_NoPositional((funcname), (args)))
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Add _PyArg_NoKwnames helper function. Patch by Dong-hee Na.
|
|
@ -146,8 +146,7 @@ range_vectorcall(PyTypeObject *type, PyObject *const *args,
|
||||||
size_t nargsf, PyObject *kwnames)
|
size_t nargsf, PyObject *kwnames)
|
||||||
{
|
{
|
||||||
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
|
Py_ssize_t nargs = PyVectorcall_NARGS(nargsf);
|
||||||
if (kwnames && PyTuple_GET_SIZE(kwnames) != 0) {
|
if (!_PyArg_NoKwnames("range", kwnames)) {
|
||||||
PyErr_Format(PyExc_TypeError, "range() takes no keyword arguments");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return range_from_array(type, args, nargs);
|
return range_from_array(type, args, nargs);
|
||||||
|
|
|
@ -709,8 +709,7 @@ static PyObject *
|
||||||
tuple_vectorcall(PyObject *type, PyObject * const*args,
|
tuple_vectorcall(PyObject *type, PyObject * const*args,
|
||||||
size_t nargsf, PyObject *kwnames)
|
size_t nargsf, PyObject *kwnames)
|
||||||
{
|
{
|
||||||
if (kwnames && PyTuple_GET_SIZE(kwnames) != 0) {
|
if (!_PyArg_NoKwnames("tuple", kwnames)) {
|
||||||
PyErr_Format(PyExc_TypeError, "tuple() takes no keyword arguments");
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2787,6 +2787,7 @@ _PyArg_UnpackStack(PyObject *const *args, Py_ssize_t nargs, const char *name,
|
||||||
|
|
||||||
|
|
||||||
#undef _PyArg_NoKeywords
|
#undef _PyArg_NoKeywords
|
||||||
|
#undef _PyArg_NoKwnames
|
||||||
#undef _PyArg_NoPositional
|
#undef _PyArg_NoPositional
|
||||||
|
|
||||||
/* For type constructors that don't take keyword args
|
/* For type constructors that don't take keyword args
|
||||||
|
@ -2813,7 +2814,6 @@ _PyArg_NoKeywords(const char *funcname, PyObject *kwargs)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int
|
int
|
||||||
_PyArg_NoPositional(const char *funcname, PyObject *args)
|
_PyArg_NoPositional(const char *funcname, PyObject *args)
|
||||||
{
|
{
|
||||||
|
@ -2831,6 +2831,23 @@ _PyArg_NoPositional(const char *funcname, PyObject *args)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
_PyArg_NoKwnames(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() takes no keyword arguments", funcname);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
_PyArg_Fini(void)
|
_PyArg_Fini(void)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue