diff options
| author | Georg Brandl <georg@python.org> | 2005-08-26 06:43:16 +0000 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2005-08-26 06:43:16 +0000 |
| commit | 66e75ac6e092fd1b5b9a7e9378928c9ec0829f32 (patch) | |
| tree | 203bed2e39badf89a4bef7e1a281f81192a8097e /Python | |
| parent | a74a655d816399e1168680c20daff3032665450d (diff) | |
| download | cpython-git-66e75ac6e092fd1b5b9a7e9378928c9ec0829f32.tar.gz | |
Disallow keyword arguments for type constructors that don't use them
(fixes #1119418).
Diffstat (limited to 'Python')
| -rw-r--r-- | Python/getargs.c | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/Python/getargs.c b/Python/getargs.c index 48f9dc481d..87d8096aa7 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -1594,3 +1594,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; +} + + + |
