Calling dunder methods manually

Rick Johnson rantingrickjohnson at gmail.com
Sat Apr 15 08:50:12 EDT 2017


On Thursday, April 13, 2017 at 2:01:41 AM UTC-5, Serhiy Storchaka wrote:
>
> __init__ is perhaps the most called dunder method. It is
> often called from the __init__ method of subclasses.

Yes, that would be one of the exceptions to the rule, but
not because the rule is unsound, but because Python's super
really sucks. Even to this day, i avoid super because the
semantics are confusing, eaisier to just write the path in
long-form. In many other languages though, super is
intelligent enough to know what scope it is in. But in any
event, i cannot think one one good reason to call dunder
methods from outside a class definition (maybe someone can
think of a few???).

> __add__ also can be called from other __add__, __iadd__ or
> __radd__.

Some people have mentioned using the methods of the operator
module to avoid calling dunders, but from the POV of
consistency, i think such a policy would be a bad idea and
just more evidence that Python's super is woefully
inadequate.

Which begs the question: "What's the point of having super
if the majority are unwilling to use it?" Hmm. I suppose
"for consistency's sake" would be the only legitimate
answer.



More information about the Python-list mailing list