Hi again,

Stefan Behnel wrote:
> Lisandro Dalcin wrote:
>> Could someone in this list try to test some simple pyx file with a
>> 'cdef class' defining some standard methods and a some 'classmethod'
>> and confirm me iff this works or not??
> 
> I'm not sure Pyrex/Cython ever supported class methods, but the following
> works for me, also in Py2.6.
[...]
> def f_plus(a):
>     return a + 1
> 
> class class1:
>     plus1 = f_plus

:) sorry, my bad, that would be the equivalent of a "staticmethod".

For the code below I get an exception at module load time:

  File "classmethod.pyx", line 15, in classmethod (classmethod.c:507)
TypeError: Class-level classmethod() can only be called on a method_descriptor
or instance method.

Is this what you meant?

Stefan


__doc__ = u"""
>>> class1.plus(1)
6
>>> class2.plus(1)
7
>>> class3.plus(1)
8
"""

def f_plus(cls, a):
    return cls.a + a

class class1:
    a = 5
    plus = classmethod(f_plus)

class class2(object):
    a = 6
    plus = classmethod(f_plus)

cdef class class3:
    a = 7
    plus = classmethod(f_plus)

_______________________________________________
Cython-dev mailing list
[email protected]
http://codespeak.net/mailman/listinfo/cython-dev

Reply via email to