super() is super [was Re: Calling dunder methods manually]
greg.ewing at canterbury.ac.nz
Sun Apr 16 00:19:45 EDT 2017
Steve D'Aprano wrote:
> But for the simple cases, using super() in Python 3 couldn't be easier.
The only "simple" use of super() is in the single inheritance
case. But that's also the case where it gains you the least
over an explicit inherited method call.
> If you have multiple inheritance, and don't use super(), then your code is
> buggy, whether you have realised it or not.
> Manually calling your parent class is only acceptable if you can absolutely
> guarantee that your class, all its parent classes, and all its subclasses
> will ONLY use single inheritance.
I don't agree with that at all. It's quite possible to write
code that uses multiple inheritance, doesn't use super() and
works perfectly correctly.
Someone else might use my class in an inheritance network in
a way that results in misbehaviour, but if it happens, *they*
wrote that bug, not me.
You could argue that I *should* write my code so that anyone
can mix it with anything in any way without having to think
about the consequences, but that sounds more like a moral
judgement than a technical argument.
More information about the Python-list