From 0a8f2996a54094507d4d99aeb5859eefc41b9f83 Mon Sep 17 00:00:00 2001 From: Anthony Baxter Date: Sun, 13 Jul 2003 13:54:34 +0000 Subject: [PATCH] Backport of rhettinger's funcobject.c 2.63, bugfix for SF bug 753451 Check the argument of classmethod is callable. (prevents classmethod(classmethod(func)) from bombing out. --- Lib/test/test_descr.py | 8 ++++++++ Objects/funcobject.c | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py index a24a0a7d7ba1..5f453626ec3f 100644 --- a/Lib/test/test_descr.py +++ b/Lib/test/test_descr.py @@ -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): diff --git a/Objects/funcobject.c b/Objects/funcobject.c index 0952d348f4aa..2afab504193f 100644 --- a/Objects/funcobject.c +++ b/Objects/funcobject.c @@ -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; -- 2.47.3