What are super()'s semantics?

Maric Michaud maric at aristote.info
Tue Sep 5 00:26:59 CEST 2006


Le lundi 04 septembre 2006 22:29, Carl Banks a écrit :
> BTW, __class__ is available to instances.  (Were you thinking of
> __bases__?)

hmmm, I guess they're not the same, are they ?

but you're right, __bases__ and some others are class attributes not available 
in instances,  I wonder where is this documented and I'm not enough familiar 
with python' source code to find this.

Also this create weird  things, like a code posted on this list, which was 
very confusing  and looked to something like :

In [24]: class A(object) :
   ....:     __class__ = list
   ....:
   ....:

In [25]: A.__class__
Out[25]: <type 'type'>

In [26]: A().__class__
Out[26]: <type 'list'>

In [27]: isinstance(A(), list) # ouch !
Out[27]: True

In [29]: type(A())
Out[29]: <class '__main__.A'>

In [30]: type(A()).mro()
Out[30]: [<class '__main__.A'>, <type 'object'>]


-- 
_____________

Maric Michaud
_____________

Aristote - www.aristote.info
3 place des tapis
69004 Lyon
Tel: +33 426 880 097



More information about the Python-list mailing list