summaryrefslogtreecommitdiff
path: root/docs/src/userguide/special_methods.rst
diff options
context:
space:
mode:
Diffstat (limited to 'docs/src/userguide/special_methods.rst')
-rw-r--r--docs/src/userguide/special_methods.rst24
1 files changed, 12 insertions, 12 deletions
diff --git a/docs/src/userguide/special_methods.rst b/docs/src/userguide/special_methods.rst
index af702f3c3..e6635b502 100644
--- a/docs/src/userguide/special_methods.rst
+++ b/docs/src/userguide/special_methods.rst
@@ -3,6 +3,9 @@
Special Methods of Extension Types
===================================
+.. include::
+ ../two-syntax-variants-used
+
This page describes the special methods currently supported by Cython extension
types. A complete list of all the special methods appears in the table at the
bottom. Some of these methods behave differently from their Python
@@ -12,7 +15,8 @@ mention.
.. Note::
Everything said on this page applies only to extension types, defined
- with the :keyword:`cdef` class statement. It doesn't apply to classes defined with the
+ with the :keyword:`cdef` class statement or decorated using ``@cclass`` decorator.
+ It doesn't apply to classes defined with the
Python :keyword:`class` statement, where the normal Python rules apply.
.. _declaration:
@@ -20,7 +24,7 @@ mention.
Declaration
------------
Special methods of extension types must be declared with :keyword:`def`, not
-:keyword:`cdef`. This does not impact their performance--Python uses different
+:keyword:`cdef`/``@cfunc``. This does not impact their performance--Python uses different
calling conventions to invoke these special methods.
.. _docstrings:
@@ -225,19 +229,15 @@ Depending on the application, one way or the other may be better:
decorator specifically for ``cdef`` classes. (Normal Python classes can use
the original ``functools`` decorator.)
- .. code-block:: cython
+.. tabs::
+
+ .. group-tab:: Pure Python
- @cython.total_ordering
- cdef class ExtGe:
- cdef int x
+ .. literalinclude:: ../../examples/userguide/special_methods/total_ordering.py
- def __ge__(self, other):
- if not isinstance(other, ExtGe):
- return NotImplemented
- return self.x >= (<ExtGe>other).x
+ .. group-tab:: Cython
- def __eq__(self, other):
- return isinstance(other, ExtGe) and self.x == (<ExtGe>other).x
+ .. literalinclude:: ../../examples/userguide/special_methods/total_ordering.pyx
.. _the__next__method: