Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit be97153

Browse files
committed
SF bug #753451: classmethod abuse --> SystemError
Check the argument to classmethod for callability. Backport candidate.
1 parent 9b15878 commit be97153

2 files changed

Lines changed: 14 additions & 0 deletions

File tree

Lib/test/test_descr.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1485,6 +1485,14 @@ def f(cls, arg): return (cls, arg)
14851485
vereq(super(D,D).goo(), (D,))
14861486
vereq(super(D,d).goo(), (D,))
14871487

1488+
# Verify that argument is checked for callability (SF bug 753451)
1489+
try:
1490+
classmethod(1).__get__(1)
1491+
except TypeError:
1492+
pass
1493+
else:
1494+
raise TestFailed, "classmethod should check for callability"
1495+
14881496
def classmethods_in_c():
14891497
if verbose: print "Testing C-based class methods..."
14901498
import xxsubtype as spam

Objects/funcobject.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,12 @@ cm_init(PyObject *self, PyObject *args, PyObject *kwds)
640640

641641
if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
642642
return -1;
643+
if (!PyCallable_Check(callable)) {
644+
PyErr_Format(PyExc_TypeError, "'%s' object is not callable",
645+
callable->ob_type->tp_name);
646+
return -1;
647+
}
648+
643649
Py_INCREF(callable);
644650
cm->cm_callable = callable;
645651
return 0;

0 commit comments

Comments
 (0)