[Cython] non-virtual methods

Robert Bradshaw robertwb at math.washington.edu
Wed Aug 24 21:20:30 CEST 2011


On Wed, Aug 24, 2011 at 12:17 PM, Vitja Makarov <vitja.makarov at gmail.com> wrote:
> 2011/8/24 Stefan Behnel <stefan_ml at behnel.de>:
>> Vitja Makarov, 24.08.2011 21:00:
>>>
>>> Recently I used cython in my project and I came with idea that
>>> sometimes virtual methods are overkill.
>>>
>>> What's about adding non-virtual decorator for c[p]def methods?
>>>
>>> cdef class Foo:
>>>      @cython.nonvirtual
>>>      cpdef int is_active(self):
>>>              return clib.obj_is_active(self._cobj)
>>
>> How does that differ from the "final" decorator?
>>
>
> I tried final classes:
> 1. Final decorator doesn't work at pxd level (compiler crash)
> 2. In this example foo call is done through virtual table
>
> cimport cython
>
> @cython.final
> cdef class Foo:
>    cdef foo(self):
>        print 'haha'
>
> def test():
>    cdef Foo a = Foo()
>    a.foo()
>
>  __pyx_t_1 = ((struct __pyx_vtabstruct_3yyy_Foo
> *)__pyx_v_a->__pyx_vtab)->foo(__pyx_v_a); if (unlikely(!__pyx_t_1))
> {__pyx_filename = __pyx_f[0]; __pyx_lineno = 12; __pyx_clineno =
> __LINE__; goto __pyx_L1_error;}
>
> 3. I can't use final decorator for methods (error reported)

I don't think "final methods" were actually implemented, it's just a
question of naming.

- Robert


More information about the cython-devel mailing list