Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #5249

Re: list equal to subclass of list?

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.dougwise.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!news.wiretrip.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
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; 'python': 0.07; ':-)': 0.07; '(it': 0.09; '*is*': 0.09; 'case).': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'humor': 0.09; 'likewise,': 0.09; 'message-id:@stoneleaf.us': 0.09; 'outlined': 0.09; 'received:gator410.hostgator.com': 0.09; 'subclass': 0.09; '~ethan~': 0.09; 'am,': 0.14; 'broken': 0.14; 'advance': 0.14; 'wrote:': 0.14; 'clear.': 0.16; 'docs.': 0.16; "doesn't.": 0.16; 'equal.': 0.16; 'precede': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'roy': 0.16; 'method.': 0.19; 'object,': 0.19; 'saying': 0.22; 'subject:list': 0.22; 'header:In-Reply-To:1': 0.22; '(and': 0.22; 'that?': 0.23; 'says': 0.25; 'compare': 0.26; 'object': 0.27; 'subject:?': 0.29; 'all.': 0.30; 'implement': 0.30; "won't": 0.30; 'comparison': 0.31; 'does': 0.31; 'it.': 0.31; 'all,': 0.31; 'to:addr:python-list': 0.32; 'sometimes': 0.33; 'clearly': 0.34; 'there': 0.35; 'header:User-Agent:1': 0.35; 'point': 0.35; 'apologies': 0.35; 'think': 0.36; 'some': 0.37; 'self': 0.37; 'should': 0.37; 'consistent': 0.38; 'eric': 0.38; 'happens': 0.38; 'returning': 0.39; 'to:addr:python.org': 0.39; 'where': 0.39; 'how': 0.39; 'attempt': 0.40; "it's": 0.40; 'header:Received:5': 0.40; 'might': 0.40; 'further': 0.62; 'received:hostgator.com': 0.64; 'special': 0.66; 'works,': 0.69; 'received:websitewelcome.com': 0.71; 'received:69.56': 0.77; '11:30': 0.84; 'want!': 0.84; 'snow': 0.91; 'unclear': 0.91; 'received:gateway02.websitewelcome.com': 0.93
Date Thu, 12 May 2011 11:29:54 -0700
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To python-list@python.org
Subject Re: list equal to subclass of list?
References <roy-B4A109.08230412052011@news.panix.com> <BANLkTik86fvQwz9bqT+wONKUmJoCrzAmjg@mail.gmail.com> <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com>
In-Reply-To <55506367-5E1C-440B-A2D4-73159339D2E6@panix.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:3391
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.1481.1305224275.9059.python-list@python.org> (permalink)
Lines 42
NNTP-Posting-Host 82.94.164.166
X-Trace 1305224276 news.xs4all.nl 81476 [::ffff:82.94.164.166]:40030
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:5249

Show key headers only | View raw


Roy Smith wrote:
> On May 12, 2011, at 11:30 AM, Eric Snow wrote:
>>
>> That definitely makes it unclear.
> 
> I don't think it's unclear at all.  It's very clear.  Clearly wrong :-)

While it is wrong (it should have 'built-in' precede the word 'types'), 
it is not wrong in the way you think -- a subclass *is* a type of its 
superclass.


>> A little further down it says that you can customize comparison with 
>> the __cmp__ special method. 
 >
> I read that as saying that if you implement __eq__(), you must make sure 
> that it returns False if self and other have different types (and 
> likewise, __ne__() should return True for that case).

Your understanding is flawed.  If your object does not know how to 
compare itself to some other object, it should return NotImplemented -- 
at that point Python will follow the rules outlined in the docs.  By 
returning NotImplemented you are allowing the other object a chance to 
perform the comparison -- after all, it might know how!  :)  If the 
other object also returns NotImplemented then (drum-roll please) they 
won't compare equal.


> The same way that it says that obj1.__lt__(obj2) must return a consistent
 > result for all types of obj1 and obj2.

Where do you see that?  I couldn't find it.

The point of being able to write your own rich comparison methods is so 
you can control what happens -- there is no "must" about it.  This is 
Python -- do what you want!  :)

~Ethan~

PS
I have a broken sense of humor -- sometimes it works, sometimes it 
doesn't.  My apologies in advance if my attempt at humor was not funny.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

list equal to subclass of list? Roy Smith <roy@panix.com> - 2011-05-12 08:23 -0400
  Re: list equal to subclass of list? Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 09:43 -0700
    Re: list equal to subclass of list? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2011-05-13 00:18 +0000
      Re: list equal to subclass of list? Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 18:04 -0700
    Re: list equal to subclass of list? Roy Smith <roy@panix.com> - 2011-05-12 21:53 -0400
  Re: list equal to subclass of list? Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 11:29 -0700
    Re: list equal to subclass of list? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-05-12 22:40 +0200
    Re: list equal to subclass of list? Roy Smith <roy@panix.com> - 2011-05-12 13:49 -0700
      Re: list equal to subclass of list? Ethan Furman <ethan@stoneleaf.us> - 2011-05-12 14:48 -0700

csiph-web