mirror of
https://github.com/python/cpython.git
synced 2025-11-29 14:31:30 +00:00
SF bug #753451: classmethod abuse --> SystemError
Check the argument to classmethod for callability. Backport candidate.
This commit is contained in:
parent
9b15878369
commit
be9715398b
2 changed files with 14 additions and 0 deletions
|
|
@ -1485,6 +1485,14 @@ def classmethods():
|
||||||
vereq(super(D,D).goo(), (D,))
|
vereq(super(D,D).goo(), (D,))
|
||||||
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():
|
def classmethods_in_c():
|
||||||
if verbose: print "Testing C-based class methods..."
|
if verbose: print "Testing C-based class methods..."
|
||||||
import xxsubtype as spam
|
import xxsubtype as spam
|
||||||
|
|
|
||||||
|
|
@ -640,6 +640,12 @@ cm_init(PyObject *self, PyObject *args, PyObject *kwds)
|
||||||
|
|
||||||
if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
|
if (!PyArg_UnpackTuple(args, "classmethod", 1, 1, &callable))
|
||||||
return -1;
|
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);
|
Py_INCREF(callable);
|
||||||
cm->cm_callable = callable;
|
cm->cm_callable = callable;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue