手册中说:
一般来说,如果您想要比较运算符的常规含义,就足够
__lt__()了__eq__()
但我看到了错误:
>       assert 2 < three
E       TypeError: unorderable types: int() < IntVar()
当我运行这个测试时:
from unittest import TestCase
class IntVar(object):
    def __init__(self, value=None):
        if value is not None: value = int(value)
        self.value = value
    def __int__(self):
        return self.value
    def __lt__(self, other):
        return self.value < other
    def __eq__(self, other):
        return self.value == other
    def __hash__(self):
        return hash(self.value)
class DynamicTest(TestCase):
    def test_lt(self):
        three = IntVar(3)
        assert three < 4
        assert 2 < three
        assert 3 == three
我很惊讶什么时候IntVar()在右边,__int__()没有被调用。我究竟做错了什么?
添加__gt__()修复此问题,但意味着我不明白订购的最低要求是什么......
谢谢,安德鲁