summaryrefslogtreecommitdiff
path: root/docs/examples/userguide/special_methods/total_ordering.py
diff options
context:
space:
mode:
Diffstat (limited to 'docs/examples/userguide/special_methods/total_ordering.py')
-rw-r--r--docs/examples/userguide/special_methods/total_ordering.py13
1 files changed, 13 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