diff options
-rw-r--r-- | Lib/test/test_descr.py | 8 | ||||
-rw-r--r-- | Objects/funcobject.c | 6 |
2 files changed, 14 insertions, 0 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index 9587596..46e3c48 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -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 diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 8f2d8df..c414bca 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -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; |