summaryrefslogtreecommitdiff
path: root/docs/examples/userguide/special_methods
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/userguide/special_methods')
-rw-r--r--docs/examples/userguide/special_methods/total_ordering.py13
-rw-r--r--docs/examples/userguide/special_methods/total_ordering.pyx13
2 files changed, 26 insertions, 0 deletions
diff --git a/docs/examples/userguide/special_methods/total_ordering.py b/docs/examples/userguide/special_methods/total_ordering.py
new file mode 100644
index 000000000..7d164d6df
--- /dev/null
+++ b/docs/examples/userguide/special_methods/total_ordering.py
@@ -0,0 +1,13 @@
+import cython
+@cython.total_ordering
+@cython.cclass
+class ExtGe:
+ x: cython.int
+
+ def __ge__(self, other):
+ if not isinstance(other, ExtGe):
+ return NotImplemented
+ return self.x >= cython.cast(ExtGe, other).x
+
+ def __eq__(self, other):
+ return isinstance(other, ExtGe) and self.x == cython.cast(ExtGe, other).x
diff --git a/docs/examples/userguide/special_methods/total_ordering.pyx b/docs/examples/userguide/special_methods/total_ordering.pyx
new file mode 100644
index 000000000..06d2ccef7
--- /dev/null
+++ b/docs/examples/userguide/special_methods/total_ordering.pyx
@@ -0,0 +1,13 @@
+import cython
+
+@cython.total_ordering
+cdef class ExtGe:
+ cdef int x
+
+ def __ge__(self, other):
+ if not isinstance(other, ExtGe):
+ return NotImplemented
+ return self.x >= (<ExtGe>other).x
+
+ def __eq__(self, other):
+ return isinstance(other, ExtGe) and self.x == (<ExtGe>other).x