super, object and type?

S

ssecorp

super(object, type)

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 on class object in module __builtin__:

class object
| The most base type
Help on class type in module __builtin__:

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

Bruno Desthuilliers

ssecorp a écrit :
<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 on class object in module __builtin__:

class object
| The most base 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:
<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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top