type, object hierarchy?

Hrvoje Niksic hniksic at xemacs.org
Mon Feb 4 04:50:10 EST 2008


7stud <bbxx789_05ss at yahoo.com> writes:

> On Feb 4, 12:49 am, Hrvoje Niksic <hnik... at xemacs.org> wrote:
>> 7stud <bbxx789_0... at yahoo.com> writes:
>> > --output:--
>> > (<class '__main__.Dog'>, <class '__main__.Mammals'>, <type 'object'>)
>>
>> > The output suggests that Dog actually is a subclass of type--despite
>> > the fact that issubclass(Dog, type) returns False.
>>
>> What was it in the output that gave you the impression that Dog is a
>> subclass of type?
>
> The fact that Dog.__mro__ produces any output at all--instead of
> producing an error.  object does not have an __mro__attribute, so
> where did Dog inherit that attribute from?  The output of dir(type)
> shoes that type has an __mro__ attribute.

I see some confusion.

For one, while Dog is not a subclass of type, it's certainly an
*instance* of type.  All instances of type have an __mro__ instance,
including object, regardless of whether dir() is aware of it.  (Try
object.__mro__, it evaluates just fine.)

Second, simply the fact that an object has an attribute doesn't say
anything about its chain of inheritance.  The final word on
inheritance is the contents of attributes such as __bases__ (shallow)
and __mro__ (deep).



More information about the Python-list mailing list