Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5246
| 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; 'definitions': 0.07; 'numeric': 0.07; 'run,': 0.07; 'correct.': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'subclass': 0.09; '~ethan~': 0.09; 'wrote:': 0.14; '"checking': 0.16; '"i\'m': 0.16; '*always*': 0.16; 'constructed': 0.16; 'empty"': 0.16; 'length)': 0.16; 'mylist': 0.16; 'precede': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'received:gateway13.websitewelcome.com': 0.16; 'rectangle': 0.16; 'roy': 0.16; 'unequal': 0.16; 'joined': 0.16; 'cc:no real name:2**0': 0.20; 'cc:2**0': 0.20; 'not.': 0.22; 'subject:list': 0.22; 'code': 0.22; 'header:In-Reply-To:1': 0.22; 'cc:addr:python- list': 0.22; 'here?': 0.23; 'objects': 0.24; "what's": 0.24; 'compare': 0.26; 'thanks.': 0.28; 'string': 0.29; 'subject:?': 0.29; 'class': 0.29; 'probably': 0.30; 'least': 0.30; 'list': 0.30; 'cc:addr:python.org': 0.31; 'do.': 0.31; 'equal': 0.31; 'url:library': 0.31; 'url:docs': 0.33; 'test': 0.33; 'lines': 0.34; 'print': 0.35; 'header:User-Agent:1': 0.35; 'should': 0.37; 'url:python': 0.37; 'either': 0.37; 'parallel': 0.38; 'thread': 0.38; 'degree': 0.38; 'url:org': 0.38; 'here,': 0.39; 'docs': 0.39; 'except': 0.39; 'whatever': 0.39; 'behavior': 0.40; 'sets': 0.40; 'header:Received:5': 0.40; 'received:hostgator.com': 0.64; 'received:websitewelcome.com': 0.71; 'incomplete,': 0.84; 'observed': 0.84; 'url:7': 0.93 |
| Date | Thu, 12 May 2011 09:43:23 -0700 |
| From | Ethan Furman <ethan@stoneleaf.us> |
| User-Agent | Thunderbird 1.5.0.10 (Windows/20070221) |
| MIME-Version | 1.0 |
| To | Roy Smith <roy@panix.com> |
| Subject | Re: list equal to subclass of list? |
| References | <roy-B4A109.08230412052011@news.panix.com> |
| In-Reply-To | <roy-B4A109.08230412052011@news.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 | |
| Cc | python-list@python.org |
| 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.1479.1305217887.9059.python-list@python.org> (permalink) |
| Lines | 58 |
| NNTP-Posting-Host | 82.94.164.166 |
| X-Trace | 1305217887 news.xs4all.nl 81476 [::ffff:82.94.164.166]:46720 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | x330-a1.tempe.blueboxinc.net comp.lang.python:5246 |
Show key headers only | View raw
Roy Smith wrote: > I recently observed in the "checking if a list is empty" thread that a > list and a subclass of list can compare equal: > > ---------------------------- > class MyList(list): > "I'm a subclass" > > l1 = [] > l2 = MyList() > > print type(l1), type(l2) > print type(l1) == type(l2) > print l1 == l2 > ---------------------------- > > when run, prints: > > <type 'list'> <class '__main__.MyList'> > False > True > > The docs say: > > [http://docs.python.org/library/stdtypes.html] > Objects of different types, except different numeric types and different > string types, never compare equal This part of the documentation is talking about built-in types, which your MyList is not. > [http://docs.python.org/release/2.7/reference/expressions.html#notin] > objects of different types *always* compare unequal Should probably have the word 'built-in' precede 'types' here, since constructed objects can do whatever they have been told to do. > In the test code above, l1 an l2 are different types, at least in the > sense that type() returns something different for each of them. --> MyList.__mro__ (<class '__main__.MyList'>, <type 'list'>, <type 'object'>) MyList is a list -- just a more specific kind of list -- as can be seen from its mro; this is analogous to a square (2 sets of parallel lines joined at 90 degree angles, both sets being the same length) also being a rectangle (2 sets of parallel lines joined at 90 degree angles). > What's the intended behavior here? Either the code is wrong or the docs > are wrong. The code is correct. ~Ethan~ PS Yes, I know my square/rectangle definitions are incomplete, thanks. ;)
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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