Inheriting from object

Bengt Richter bokr at oz.net
Sat Jul 2 14:06:18 EDT 2005


On Thu, 30 Jun 2005 08:54:31 -0700, Scott David Daniels <Scott.Daniels at Acm.Org> wrote:

>Sion Arrowsmith wrote:
>> ... And if you were to do so, surely:
>> class foo(object):
>>     def __init__(self, *args, **kwargs):
>> 	super(foo, self).__init__(self)
>> 
>> would be the preferred way to go?
>> 
>Or, perhaps:
>     class foo(object):
>         def __init__(self, *args, **kwargs):
>             super(foo, self).__init__(self, *args, **kwargs)
>             ...
>
Doesn't super(foo, self).__init__ return a bound method, so you don't
need to pass self again? I.e.,
              super(foo, self).__init__(*args, **kwargs)

BTW, there's something about referring to type(self) by its not
always dependably bound (though usually global) name that bothers me.

I wonder if the above common use of super could be implemented as a property of object,
so you'd normally inherit it and be able to write
    self.super.__init__(*args, **kwargs)  # (maybe spell it self.__super__.__init__(...) I suppose)

I.e., self.__super__ would effectively return the equivalent of
    super(type(self), self)

(I think Michele Simionato may have posted some idea like this early on that
I didn't really follow, but maybe my subconscious snagged and garbled ;-)

Regards,
Bengt Richter



More information about the Python-list mailing list