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


Groups > comp.lang.python > #5268

Re: list equal to subclass of list?

Date 2011-05-12 14:48 -0700
From Ethan Furman <ethan@stoneleaf.us>
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> <mailman.1481.1305224275.9059.python-list@python.org> <925edfdd-51c7-400b-af2b-4171779779c8@r35g2000prj.googlegroups.com>
Newsgroups comp.lang.python
Message-ID <mailman.1498.1305236181.9059.python-list@python.org> (permalink)

Show all headers | View raw


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"
> 
> class List_B(list):
>     "Another list subclass"
> 
> a = List_A()
> b = List_B()
> print a == b
> 
> It prints "True".  Neither a nor b are a type of the other:
> 
> print isinstance(List_A, List_B)
> print isinstance(List_B, List_A)
> 
> False
> False

Okay, considering:
     List_A is a user-defined type.
     List_B is a user-defined type.
     Both are sub-classes of list.
     Corrected documentation (which says 'built-in types' etc, etc) says 
nothing about user-defined types not being able to be equal to each other
     neither List_A nor List_B have overridden the __eq__ method, so 
list.__eq__ will be used...

conclusion:
     if they have equal elements in the same order, they will compare 
equal since they are, in fact, list's

Do you not get the same conclusion?

~Ethan~

Back to comp.lang.python | Previous | NextPrevious 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