Я хочу класс Inf
такой, чтобы я мог написать код, такой как
>>> class Inf:
... pass # TODO
...
>>> Inf > 3
True
Я знаю, что я могу сделать это
>>> class Inf:
... def __gt__(self, other):
... return True
... def __lt__(self, other):
... return False
... def __eq__(self, other):
... return type(self) == type(other)
...
>>> inf = Inf()
>>> inf > 3
True
Но я хочу класс сам для возможности сравнения с int
с, а не его экземпляр для возможности сравнения с int
с.
Я хочу иметь возможностьделать Inf > 3 # True
, а не Inf() > 3 # True
.
Это моя попытка, которая не работает:
>>> class Inf:
... @classmethod
... def __gt__(cls, other):
... return True
... ... # more classmethods
...
>>> Inf > 3
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: type() < int()
Halp plz!