Cython Error: Cannot call a static method on an instance variable.

179 views
Skip to first unread message

slabbe

unread,
Jun 18, 2015, 10:19:40 AM6/18/15
to sage-s...@googlegroups.com
I would like to do this in Cython:

    sage: class Fruit(object):
    ....:     @staticmethod
    ....:     def yo(a):
    ....:         return a
    ....:     def using_yo(self, a):
    ....:         return self.yo(a)
    sage: f = Fruit()
    sage: f.using_yo(1)
    1

But it does not work (why?) :

    sage: cython("""
    sage: cdef class Fruit(object):
    ....:     @staticmethod
    ....:     cdef yo(a):
    ....:         return a
    ....:     def using_yo(self, a):
    ....:         return self.yo(a)
    sage: """)
    RuntimeError: Error converting tmp_PUV0E1.spyx to C:


    Error compiling Cython file:
    ------------------------------------------------------------
    ...
    cdef class Fruit(object):
        @staticmethod
        cdef yo(a):
            return a
        def using_yo(self, a):
            return self.yo(a)
                         ^
    ------------------------------------------------------------

    _9165_tmp_PUV0E1_spyx_0.pyx:12:22: Cannot call a static method on an instance variable.

Jeroen Demeyer

unread,
Jun 18, 2015, 11:11:32 AM6/18/15
to sage-s...@googlegroups.com
No idea, it looks like this is simply not supported:

https://github.com/cython/cython/blob/master/Cython/Compiler/ExprNodes.py#L4659
Reply all
Reply to author
Forward
0 new messages