summaryrefslogtreecommitdiff
path: root/docs/examples/userguide/special_methods/total_ordering.py
blob: 7d164d6dfbe909b2b575cf9f2407da1b0600a4a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
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