diff Python/getargs.c @ 35449:1fdfd0130e28 legacy-trunk

Disallow keyword arguments for type constructors that don't use them. (fixes bug #1119418)
author Georg Brandl <georg@python.org>
date Fri, 26 Aug 2005 06:42:30 +0000
parents 13d5caa1e9d0
children 9b7d117eb4bc
line wrap: on
line diff
--- a/Python/getargs.c	Thu Aug 25 22:40:16 2005 +0000
+++ b/Python/getargs.c	Fri Aug 26 06:42:30 2005 +0000
@@ -1595,3 +1595,29 @@
 	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;
+}
+
+
+