Commit 66ca26c4 authored by Stefan Behnel's avatar Stefan Behnel

repair CyFunction behaviour for staticmethods and add tests for classmethods

parent 0bc33758
......@@ -630,7 +630,7 @@ static CYTHON_INLINE PyObject *__Pyx_CyFunction_Call(PyObject *func, PyObject *a
static PyObject *__Pyx_CyFunction_CallAsMethod(PyObject *func, PyObject *args, PyObject *kw) {
PyObject *result;
__pyx_CyFunctionObject *cyfunc = (__pyx_CyFunctionObject *) func;
if (cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) {
if ((cyfunc->flags & __Pyx_CYFUNCTION_CCLASS) && !(cyfunc->flags & __Pyx_CYFUNCTION_STATICMETHOD)) {
Py_ssize_t argc;
PyObject *new_args;
PyObject *self;
......
__doc__ = u"""
>>> class1.view()
class1
>>> class1.plus(1)
6
>>> class1.view()
class1
>>> class1().view()
class1
>>> class1.bview()
class1
>>> class1().bview()
class1
>>> class2.view()
class2
>>> class2.plus(1)
7
>>> class3.view()
class3
>>> class3.bview()
class3
>>> class3().bview()
class3
>>> class3.plus(1)
8
>>> class4.view()
class4
>>> class5.view()
class5
"""
cimport cython
def f_plus(cls, a):
return cls.a + a
class class1:
a = 5
plus = classmethod(f_plus)
......@@ -27,6 +43,12 @@ class class1:
print cls.__name__
view = classmethod(view)
@classmethod
@cython.binding(True)
def bview(cls):
print cls.__name__
class class2(object):
a = 6
plus = classmethod(f_plus)
......@@ -34,6 +56,7 @@ class class2(object):
print cls.__name__
view = classmethod(view)
cdef class class3:
a = 7
plus = classmethod(f_plus)
......@@ -41,10 +64,17 @@ cdef class class3:
print cls.__name__
view = classmethod(view)
@classmethod
@cython.binding(True)
def bview(cls):
print cls.__name__
class class4:
@classmethod
def view(cls):
print cls.__name__
class class5(class4):
pass
......@@ -7,8 +7,16 @@ __doc__ = u"""
2
>>> class4.plus1(1)
2
>>> class4().plus1(1)
2
>>> class4.bplus1(1)
2
>>> class4().bplus1(1)
2
"""
cimport cython
def f_plus(a):
return a + 1
......@@ -26,6 +34,12 @@ class class4:
def plus1(a):
return a + 1
@staticmethod
@cython.binding(True)
def bplus1(a):
return a + 1
def nested_class():
"""
>>> cls = nested_class()
......@@ -44,6 +58,7 @@ def nested_class():
return a + 1
return class5
cdef class BaseClass(object):
"""
Test cdef static methods with super() and Python subclasses
......@@ -64,9 +79,11 @@ cdef class BaseClass(object):
print arg1
@staticmethod
@cython.binding(True)
def mystaticmethod2(a, b, c):
print a, b, c
cdef class SubClass(BaseClass):
"""
>>> obj = SubClass()
......@@ -83,6 +100,7 @@ cdef class SubClass(BaseClass):
print arg1
super().mystaticmethod(self, arg1 + 1)
class SubSubClass(SubClass):
"""
>>> obj = SubSubClass()
......@@ -121,6 +139,7 @@ cdef class ArgsKwargs(object):
"""
return args + tuple(sorted(kwargs.items()))
class StaticmethodSubclass(staticmethod):
"""
>>> s = StaticmethodSubclass(None)
......
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