list equal to subclass of list?

Roy Smith roy at panix.com
Thu May 12 16:49:00 EDT 2011


On May 12, 2:29 pm, Ethan Furman <et... at 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




More information about the Python-list mailing list