Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.000 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'subject:error': 0.03; 'sufficient': 0.05; 'implements': 0.09; 'none)': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'types:': 0.09; 'python': 0.11; 'def': 0.12; '__lt__': 0.16; '__lt__(self,': 0.16; 'received:80.91.229.3': 0.16; 'received:dip0.t-ipconnect.de': 0.16; 'received:plane.gmane.org': 0.16; 'received:t-ipconnect.de': 0.16; 'self.x,': 0.16; 'self.y': 0.16; 'typeerror:': 0.16; 'y):': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'url:dev': 0.24; "i've": 0.25; 'header:X-Complaints-To:1': 0.27; '"",': 0.31; '>>>>': 0.31; 'name;': 0.31; 'file': 0.32; 'class': 0.32; 'probably': 0.32; 'url:python': 0.33; '(most': 0.33; 'skip:_ 10': 0.34; 'but': 0.35; 'there': 0.35; 'false': 0.36; 'method': 0.36; 'hi,': 0.36; 'url:org': 0.36; 'should': 0.36; 'error.': 0.37; 'two': 0.37; 'expected': 0.38; 'url:library': 0.38; 'to:addr :python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'even': 0.60; 'default': 0.69; 'special': 0.74 X-Injected-Via-Gmane: http://gmane.org/ To: python-list@python.org From: Peter Otten <__peter__@web.de> Subject: Re: unorderable error: less ok, equal ok, less-or-equal gives unorderable error! Date: Mon, 30 Jun 2014 21:34:25 +0200 Organization: None References: Mime-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 7Bit X-Gmane-NNTP-Posting-Host: p57bdae78.dip0.t-ipconnect.de User-Agent: KNode/4.11.5 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 55 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1404156879 news.xs4all.nl 2914 [2001:888:2000:d::a6]:59449 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:73759 RainyDay wrote: > Hi, in python 3.4.1, I get this surpising behaviour: > >>>> l=Loc(0,0) >>>> l2=Loc(1,1) >>>> l>l2 > False >>>> l True >>>> l<=l2 > Traceback (most recent call last): > File "", line 1, in > TypeError: unorderable types: Loc() <= Loc() >>>> l==l2 > False >>>> l True > > Loc implements both __lt__ and __eq__, which should be enough (?), These two methods should be sufficient if you use the functools.total_ordering class decorator, see https://docs.python.org/dev/library/functools.html#functools.total_ordering > but even after I've added __lte__, I still have the error. There is no special method of that name; it should probably be __le__(). > > 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) Note that None is not a good default when _loc is expected to be a tuple: >>> None < () Traceback (most recent call last): File "", line 1, in TypeError: unorderable types: NoneType() < tuple() > > def __lt__(self, other): > return self._loc < other._loc > > - andrei