Commit 7c7cc9da authored by Robert Bradshaw's avatar Robert Bradshaw

Docs on static methods.

parent fe73aba5
......@@ -345,7 +345,7 @@ functions, C methods are declared using :keyword:`cdef` or :keyword:`cpdef` inst
:keyword:`def`. C methods are "virtual", and may be overridden in derived
extension types. In addition, :keyword:`cpdef` methods can even be overridden by python
methods when called as C method. This adds a little to their calling overhead
compared to a :keyword:`cdef` methd::
compared to a :keyword:`cdef` method::
# pets.pyx
cdef class Parrot:
......@@ -382,6 +382,23 @@ method using the usual Python technique, i.e.::
Parrot.describe(self)
`cdef` methods can be declared static by using the @staticmethod decorator.
This can be especially useful for constructing classes that take non-Python
compatible types.::
cdef class OwnedPointer:
cdef void* ptr
cdef __dealloc__(self):
if ptr != NULL:
free(ptr)
@staticmethod
cdef create(void* ptr):
p = OwnedPointer()
p.ptr = ptr
return ptr
Forward-declaring extension types
===================================
......
......@@ -529,9 +529,10 @@ If the Rectangle class has a static member:
};
}
you can declare it as a function living in the class namespace, i.e.::
you can declare it using the Python @staticmethod decorator, i.e.::
cdef extern from "Rectangle.h" namespace "shapes::Rectangle":
cdef extern from "Rectangle.h" namespace "shapes":
@staticmethod
void do_something()
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment