mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
Disallow keyword arguments for type constructors that don't use them.
(fixes bug #1119418)
This commit is contained in:
parent
bd77da6dab
commit
02c42871cf
13 changed files with 100 additions and 13 deletions
|
@ -1595,3 +1595,29 @@ PyArg_UnpackTuple(PyObject *args, char *name, int min, int max, ...)
|
|||
va_end(vargs);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/* For type constructors that don't take keyword args
|
||||
*
|
||||
* Sets a TypeError and returns 0 if the kwds dict is
|
||||
* not emtpy, returns 1 otherwise
|
||||
*/
|
||||
int
|
||||
_PyArg_NoKeywords(char *funcname, PyObject *kw)
|
||||
{
|
||||
if (kw == NULL)
|
||||
return 1;
|
||||
if (!PyDict_CheckExact(kw)) {
|
||||
PyErr_BadInternalCall();
|
||||
return 0;
|
||||
}
|
||||
if (PyDict_Size(kw) == 0)
|
||||
return 1;
|
||||
|
||||
PyErr_Format(PyExc_TypeError, "%s does not take keyword arguments",
|
||||
funcname);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue