type, object hierarchy?
7stud
bbxx789_05ss at yahoo.com
Mon Feb 4 04:35:41 EST 2008
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. Some of the evidence
suggests this might be the hierarchy:
object ---> type
|
V
Mammal
|
V
Dog
But since Dog seems to inherit __mro__ from type, that hierarchy does
not appear to be correct. Rather this hierarchy seems more likely:
object
|
V
type
|
V
Mammal
|
V
Dog
> And if you want to really blow your mind,
>
> print isinstance(type, object) # True
> print isinstance(object, type) # True
>
Yep, I investigated that before I posted. It doesn't seem to fit with
the latter hierarchy.
More information about the Python-list
mailing list