[docs] [issue21814] object.__setattr__ or super(...).__setattr__?
report at bugs.python.org
Sat Jun 21 04:14:15 CEST 2014
Raymond Hettinger added the comment:
> Wouldn't it be more consistent for new-style classes,
> instead of calling "object.__setattr__(self, name, value)",
> to call "super(<ClassName>, self).__setattr__(name, value)"?
That's not always the right thing to do. Calling object.__setattr__ gives a known, guaranteed behavior. Using super however relies on an MRO calculation that may send the super call outside the inheritance tree to a methods that wasn't expecting to be called.
Put another way, super was designed for cooperative multiple inheritance with implies an element of coordinated cooperation that isn't always present.
I think the current advice should stand. We aren't advising people to always use super instead of calling a parent class method directly. Part of the reason is that super can be much trickier that people expect.
Also, in Python 2.7 super() doesn't have the same magical but clean invocation it has in Python 3. The two argument form isn't as elegant looking or as easy to get right.
assignee: docs at python -> rhettinger
Python tracker <report at bugs.python.org>
More information about the docs