A
andrew cooke
hi,
please, what am i doing wrong here? the docs say http://docs.python.org/release/3.1.3/library/stdtypes.html#comparisons "in general, __lt__() and __eq__() are sufficient, if you want the conventional meanings of the comparison operators" but i am seeing
with this test:
class IntVar(object):
def __init__(self, value=None):
if value is not None: value = int(value)
self.value = value
def setter(self):
def wrapper(stream_in, thunk):
self.value = thunk()
return self.value
return wrapper
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
so what am i missing?
thanks,
andrew
please, what am i doing wrong here? the docs say http://docs.python.org/release/3.1.3/library/stdtypes.html#comparisons "in general, __lt__() and __eq__() are sufficient, if you want the conventional meanings of the comparison operators" but i am seeing
E TypeError: unorderable types: int() < IntVar()assert 2 < three
with this test:
class IntVar(object):
def __init__(self, value=None):
if value is not None: value = int(value)
self.value = value
def setter(self):
def wrapper(stream_in, thunk):
self.value = thunk()
return self.value
return wrapper
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
so what am i missing?
thanks,
andrew