super question

xtian xtian at
Tue Apr 8 00:33:36 CEST 2003

danra at (Danra) wrote in message news:<fd1c664e.0304071056.31a0d377 at>...
> Hi,
> Here's my experience with 'super':
> >>> class b:
> 	pass

Super only works on new-style classes.
Because you don't subclass anything, b is an old-style class. To make
b a new-style class, b should subclass object. You can also create a
new-style class by subclassing a builtin type, like list or str.

> >>> class c(b):
> 	pass
> >>> super(c)
> Traceback (most recent call last):
>   File "<pyshell#6>", line 1, in ?
>     super(c)
> TypeError: super() argument 1 must be type, not classobj

A new-style class is a type (ie, type(newstyleclass) == <type 'type'>)
while an old-style class is not (type(b) == <type 'class'>). The error
message is a bit cryptic.

Hope that clarifies things - once the type-class unification is
complete, this distinction will go away (I think).


More information about the Python-list mailing list