]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of rhettinger's funcobject.c 2.63, bugfix for SF bug 753451
authorAnthony Baxter <anthonybaxter@gmail.com>
Sun, 13 Jul 2003 13:54:34 +0000 (13:54 +0000)
committerAnthony Baxter <anthonybaxter@gmail.com>
Sun, 13 Jul 2003 13:54:34 +0000 (13:54 +0000)
Check the argument of classmethod is callable. (prevents
classmethod(classmethod(func)) from bombing out.

Lib/test/test_descr.py
Objects/funcobject.c

index a24a0a7d7ba15b6cb79c50f9ddf18e5721920a01..5f453626ec3f9f5a8b74aeed554165cca51a19d0 100644 (file)
@@ -1287,6 +1287,14 @@ def classmethods():
     vereq(super(D,D).goo(), (D,))
     vereq(super(D,d).goo(), (D,))
 
+    # Verify that argument is checked for callability (SF bug 753451)
+    try:
+        classmethod(1).__get__(1)
+    except TypeError:
+        pass
+    else:
+        raise TestFailed, "classmethod should check for callability"
+
 def staticmethods():
     if verbose: print "Testing static methods..."
     class C(object):
index 0952d348f4aa8b165c2007dedb1b2ae4b340021c..2afab504193fd42e3a0f788c4e0930407f593a83 100644 (file)
@@ -611,6 +611,12 @@ cm_init(PyObject *self, PyObject *args, PyObject *kwds)
 
        if (!PyArg_ParseTuple(args, "O:callable", &callable))
                return -1;
+       if (!PyCallable_Check(callable)) {
+               PyErr_Format(PyExc_TypeError, "'%s' object is not callable",
+                    callable->ob_type->tp_name);
+               return -1;
+       }
+       
        Py_INCREF(callable);
        cm->cm_callable = callable;
        return 0;