]> granicus.if.org Git - python/commitdiff
Allow new.function() called with explicit 3rd arg of None, as
authorGuido van Rossum <guido@python.org>
Mon, 13 Nov 2000 20:29:20 +0000 (20:29 +0000)
committerGuido van Rossum <guido@python.org>
Mon, 13 Nov 2000 20:29:20 +0000 (20:29 +0000)
documented, and as is reasonable (since it is optional, but there's
another argument following it that may require you to specify a
value).  This solves SF bug 121887.

Modules/newmodule.c

index 456e44062ef3949fb3314e4e04e425dd82f70a48..21b82ef824de3cf0ea2052ac856acd81732a064c 100644 (file)
@@ -70,12 +70,17 @@ new_function(PyObject* unused, PyObject* args)
        PyObject* defaults = Py_None;
        PyFunctionObject* newfunc;
 
-       if (!PyArg_ParseTuple(args, "O!O!|SO!:function",
+       if (!PyArg_ParseTuple(args, "O!O!|OO!:function",
                              &PyCode_Type, &code,
                              &PyDict_Type, &globals,
                              &name,
                              &PyTuple_Type, &defaults))
                return NULL;
+       if (name != Py_None && !PyString_Check(name)) {
+               PyErr_SetString(PyExc_TypeError,
+                               "arg 3 (name) must be None or string");
+               return NULL;
+       }
 
        newfunc = (PyFunctionObject *)PyFunction_New(code, globals);
        if (newfunc == NULL)