From: nbruin Date: Thu, 11 Apr 2013 02:47:44 +0000 (-0700) Subject: explain difference between cdef and cpdef X-Git-Tag: 0.19b2~8^2~2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6331b6385962c1cd0e0d4ee78b56dc589726adb5;p=platform%2Fupstream%2Fpython-cython.git explain difference between cdef and cpdef --- diff --git a/docs/src/quickstart/cythonize.rst b/docs/src/quickstart/cythonize.rst index d0f7100..72270b0 100644 --- a/docs/src/quickstart/cythonize.rst +++ b/docs/src/quickstart/cythonize.rst @@ -94,13 +94,16 @@ object or if it is guaranteed that an exception will not be raised within the function call. A side-effect of cdef is that the function is no longer available from -Python-space, as Python wouldn't know how to call it. Using the -``cpdef`` keyword instead of cdef, a Python wrapper is also created, -so that the function is available both from Cython (fast, passing -typed values directly) and from Python (wrapping values in Python -objects). +Python-space, as Python wouldn't know how to call it. It is also no +longer possible to change ``f` at runtime. -Note also that it is no longer possible to change ``f`` at runtime. +Using the ``cpdef`` keyword instead of ``cdef``, a Python wrapper is also +created, so that the function is available both from Cython (fast, passing +typed values directly) and from Python (wrapping values in Python +objects). In fact, ``cpdef`` does not just provide a Python wrapper, it also +installs logic to allow the method to be overridden by python methods, even +when called from within cython. This does add a tiny overhead compared to ``cdef`` +methods. Speedup: 150 times over pure Python.