[Cython] Virtual cpdef methods
Robert Bradshaw
robertwb at math.washington.edu
Mon Jun 20 11:31:05 EDT 2016
All methods (cdef, cpdef, and def) are virtual by default in Cython,
just like Python.
Sounds like you want a cdef function to me. You can override a cdef
function with a cpdef function for any subclass that wishing to expose
it to Python.
On Mon, Jun 20, 2016 at 6:08 AM, Jeroen Demeyer <jdemeyer at cage.ugent.be> wrote:
> Hello,
>
> I would like to have a "virtual" cpdef method: something which allows a fast
> Cython call *when implemented* but without a default implementation.
>
> The most simple implementation would be a "cpdef" method but without an
> entry for the method in the Python method table.
>
> Of course, the "cdef" part needs to be implemented by the user (you need to
> put something in the vtab). For my purposes, something like "raise
> AttributeError" would be sufficient.
>
> 1. Can this be accomplished currently in Cython?
>
> 2. Is this something that makes sense to add to Cython?
>
> 3. What do you think of the following syntax?
>
> cdef class MyClass(object):
> cpdef virtual_method(self):
> # implementation of "cdef" part ...
>
> del virtual_method # don't put virtual_method in the method table
> _______________________________________________
> cython-devel mailing list
> cython-devel at python.org
> https://mail.python.org/mailman/listinfo/cython-devel
More information about the cython-devel
mailing list