]> granicus.if.org Git - python/commitdiff
SF bug #753451: classmethod abuse --> SystemError
authorRaymond Hettinger <python@rcn.com>
Wed, 18 Jun 2003 01:13:41 +0000 (01:13 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 18 Jun 2003 01:13:41 +0000 (01:13 +0000)
Check the argument to classmethod for callability.

Backport candidate.

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

index 9587596187469874ec55e9c15955d8cba569ffff..46e3c4837a43e18e1f2455e7f9ac84215d25f976 100644 (file)
@@ -1485,6 +1485,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 classmethods_in_c():
     if verbose: print "Testing C-based class methods..."
     import xxsubtype as spam
index 8f2d8df509cbf79fc23f888dd8cd6984200fbe16..c414bcaab8682a484cad9de808415068db9bb206 100644 (file)
@@ -640,6 +640,12 @@ cm_init(PyObject *self, PyObject *args, PyObject *kwds)
 
        if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &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;