Commit 76048959 authored by da-woods's avatar da-woods Committed by Stefan Behnel

classmethod() should fall back to calling PyClassMethod_New() instead of...

classmethod() should fall back to calling PyClassMethod_New() instead of deciding for itself that the type is invalid. (GH-3660)
parent 7a646983
......@@ -1317,16 +1317,7 @@ static PyObject* __Pyx_Method_ClassMethod(PyObject *method) {
// python classes
return PyClassMethod_New(PyMethod_GET_FUNCTION(method));
}
else if (PyCFunction_Check(method)) {
return PyClassMethod_New(method);
}
#ifdef __Pyx_CyFunction_USED
else if (__Pyx_CyFunction_Check(method)) {
else {
return PyClassMethod_New(method);
}
#endif
PyErr_SetString(PyExc_TypeError,
"Class-level classmethod() can only be called on "
"a method_descriptor or instance method.");
return NULL;
}
......@@ -9,6 +9,10 @@ class1
class1
>>> class1().bview()
class1
>>> class1().cview()
class1
>>> class1().cview("XX")
class1XX
>>> class2.view()
class2
......@@ -35,6 +39,12 @@ cimport cython
def f_plus(cls, a):
return cls.a + a
def second_decorator(f):
# note - a class, not a function (didn't pass Cython's test in __Pyx_Method_ClassMethod)
class C:
def __call__(self, *args):
return f(*args)
return C()
class class1:
a = 5
......@@ -48,6 +58,11 @@ class class1:
def bview(cls):
print cls.__name__
@classmethod
@second_decorator
def cview(cls, s=""):
print cls.__name__+s
class class2(object):
a = 6
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment