list equal to subclass of list?

2011-05-12 Thread Roy Smith
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

Re: list equal to subclass of list?

2011-05-12 Thread Algis Kabaila
On Thursday 12 May 2011 22:23:04 Roy Smith wrote: 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

Re: list equal to subclass of list?

2011-05-12 Thread Eric Snow
On Thu, May 12, 2011 at 6:23 AM, Roy Smith r...@panix.com wrote: 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

Re: list equal to subclass of list?

2011-05-12 Thread Roy Smith
On May 12, 2011, at 11:30 AM, Eric Snow wrote: On Thu, May 12, 2011 at 6:23 AM, Roy Smith r...@panix.com wrote: 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

Re: list equal to subclass of list?

2011-05-12 Thread Ethan Furman
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

Re: list equal to subclass of list?

2011-05-12 Thread Ethan Furman
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

Re: list equal to subclass of list?

2011-05-12 Thread Thomas 'PointedEars' Lahn
Ethan Furman wrote: 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. Now that was very unpythonic. Know where your roots are! :) -- PointedEars Bitte keine Kopien per E-Mail. / Please do not Cc:

Re: list equal to subclass of list?

2011-05-12 Thread Roy Smith
On May 12, 2:29 pm, Ethan Furman et...@stoneleaf.us wrote: 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. Well, consider this: class List_A(list): A list subclass class

Re: list equal to subclass of list?

2011-05-12 Thread Ethan Furman
Roy Smith wrote: On May 12, 2:29 pm, Ethan Furman et...@stoneleaf.us wrote: 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. Well, consider this: class List_A(list): A list subclass

Re: list equal to subclass of list?

2011-05-12 Thread Steven D'Aprano
On Thu, 12 May 2011 09:43:23 -0700, Ethan Furman wrote: 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

Re: list equal to subclass of list?

2011-05-12 Thread Ethan Furman
Steven D'Aprano wrote: On Thu, 12 May 2011 09:43:23 -0700, Ethan Furman wrote: 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

Re: list equal to subclass of list?

2011-05-12 Thread Roy Smith
In article mailman.1479.1305217887.9059.python-l...@python.org, Ethan Furman et...@stoneleaf.us wrote: [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