Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #5230
| From | Roy Smith <roy@panix.com> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | list equal to subclass of list? |
| Date | 2011-05-12 08:23 -0400 |
| Organization | PANIX Public Access Internet and UNIX, NYC |
| Message-ID | <roy-B4A109.08230412052011@news.panix.com> (permalink) |
I have a vague feeling this may have been discussed a long time ago, but
I can't find the thread, so I'll bring it up again.
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
[http://docs.python.org/release/2.7/reference/expressions.html#notin]
objects of different types (emphasis)always compare unequal
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. What's
the intended behavior here? Either the code is wrong or the docs are
wrong.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar
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