unorderable error: less ok, equal ok, less-or-equal gives unorderable error!
RainyDay
andrei.avk at gmail.com
Mon Jun 30 15:12:42 EDT 2014
Hi, in python 3.4.1, I get this surpising behaviour:
>>> l=Loc(0,0)
>>> l2=Loc(1,1)
>>> l>l2
False
>>> l<l2
True
>>> l<=l2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: unorderable types: Loc() <= Loc()
>>> l==l2
False
>>> l<l2 or l==l2
True
Loc implements both __lt__ and __eq__, which should be enough (?),
but even after I've added __lte__, I still have the error.
implementation:
class Loc:
def __init__(self, x, y):
self._loc = x, y
self.x, self.y = x, y
def __eq__(self, other):
return self._loc == getattr(other, "_loc", None)
def __lt__(self, other):
return self._loc < other._loc
- andrei
More information about the Python-list
mailing list