ordering with duck typing in 3.1
Thomas Rachel
nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Sat Apr 7 09:35:36 EDT 2012
Am 07.04.2012 14:23 schrieb andrew cooke:
> 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)
> so what am i missing?
If I don't confuse things, I think you are missing a __gt__() in your
IntVar() class.
This is because first, a '2 < three' is tried with 2.__lt__(three). As
this fails due to the used types, it is reversed: 'three > 2' is
equivalent. As your three doesn't have a __gt__(), three.__gt__(2) fails
as well.
Thomas
More information about the Python-list
mailing list