Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

super, object and type?

0 views
Skip to first unread message

ssecorp

unread,
Aug 12, 2008, 1:14:05 PM8/12/08
to
>>> super(object, type)
<super: <class 'object'>, <type object>>
>>> super(type, object)
<super: <class 'type'>, <type object>>
>>>

how can both work?

they can't both be the superclass of each other right? or is it some
sort of mutually recursive definition?


>>> help(object)
Help on class object in module __builtin__:

class object
| The most base type

>>> help(type)
Help on class type in module __builtin__:

class type(object)
| type(object) -> the object's type
| type(name, bases, dict) -> a new type

Calvin Spealman

unread,
Aug 12, 2008, 1:35:07 PM8/12/08
to ssecorp, pytho...@python.org
object and type both are instances of type. Yes, type is an instance of itself.

type inherits object.

> --
> http://mail.python.org/mailman/listinfo/python-list
>

--
Read my blog! I depend on your acceptance of my opinion! I am interesting!
http://techblog.ironfroggy.com/
Follow me if you're into that sort of thing: http://www.twitter.com/ironfroggy

Bruno Desthuilliers

unread,
Aug 12, 2008, 2:04:26 PM8/12/08
to
ssecorp a écrit :

>>>> super(object, type)
> <super: <class 'object'>, <type object>>
>>>> super(type, object)
> <super: <class 'type'>, <type object>>
>
> how can both work?
>
> they can't both be the superclass of each other right? or is it some
> sort of mutually recursive definition?
>

some sort, yes:

>
>
>>>> help(object)
> Help on class object in module __builtin__:
>
> class object
> | The most base type
>
>>>> help(type)
> Help on class type in module __builtin__:
>
> class type(object)
> | type(object) -> the object's type
> | type(name, bases, dict) -> a new type

You forgot:
>>> type(object)
<type 'type'>
>>>
>>> type(type)
<type 'type'>
>>>

<apply-only to="new-style classes">

As you can see, object is both the superclass *and* an instance of type,
and type is an instance of itself.

This kind of situation is common in OOPLs having metaclasses and a
unique common base class.

A class is an object, so it have to be an instance of a class. If you
don't make the base metaclass an instance of itself, you have an
infinite recursion. Also, since a class is an object and there's one
unique common base class for all other classes, the base metaclass has
to subclass this class (else it wouldn't be the unique common base
class...).

</apply-only>

HTH

0 new messages