Accessing parent objects

Antoon Pardon antoon.pardon at vub.be
Mon Mar 26 04:43:25 EDT 2018


On 25-03-18 06:29, Steven D'Aprano wrote:
> Python 3 is now six point releases in (and very soon to have a seventh,
> 3.7 being in beta as we speak). It is stable, feature-rich, and a joy to 
> work in. As well as a heap of great new features, there have been a 
> metric tonne of performance improvements, making Python 3 faster than 2.7 
> for many tasks, e.g.

But did they start up cleaning the standard library yet? I'll confess I'm
only using 3.5 but when I go through the standard library I see a lot of
classes still using the old style of calling the parant method, which
makes it more difficult to use in a multiple inheritance scheme. Those
that don't inheret, don't call super themselves, which makes them also
more difficult to use in a multiple inheritance scheme.
 

> For comparison, here's how Python's super works in 3.x:
>
>     def method(self, spam, eggs, cheese):
>         result = super().method(spam, eggs, cheese)
>
> In other words, you must explicitly state the method you are calling, and 
> give the arguments you want to pass on. Of course you can manipulate or 
> remove those arguments as needed, or add new ones:

One of the problems with this is that when you go through the mro you will
ultimatly end up calling object.method(self, spam, eggs, cheese) which will
thrown an exception like: AttributeError: 'super' object has no attribute 'method'

So I find your example misleading. It is just one step, and you need
a carefully designed hierarchy to make it work correctly and incorporating
standard library classe into that hierarchy is not self-evident.

-- 
Antoon




More information about the Python-list mailing list