On 14/04/2011 15:18, Ronald Oussoren wrote:
On 14 Apr, 2011, at 15:09, Ricardo Kirkner wrote:
Hi all,
I recently stumbled upon an issue with a class in the mro chain not
calling super, therefore breaking the chain (ie, further base classes
along the chain didn't get called).
I understand it is currently a requirement that all classes that are
part of the mro chain behave and always call super. My question is,
shouldn't/wouldn't it be better,
if python took ownership of that part, and ensured all classes get
called, even if some class misbehaved?
Not calling a method on super isn't necessarily misbehavior. It would be odd
to not call super in __init__, but for other methods not calling the superclass
implementation is fairly common.
Right, but where you have an inheritance chain where all the classes do
call super but one doesn't then you can get breakage. This is a problem
where you want to use multiple inheritance but a parent class of *one*
of the classes doesn't call super. Not only does the super of its
parents not get called - but the chain stops and other methods (in
another branch of the inheritance tree) also don't get called. And if
the base classes are not all under your control there maybe no fix -
except possibly monkey patching.
Ricardo isn't suggesting that Python should always call super for you,
but when you *start* the chain by calling super then Python could ensure
that all the methods are called for you. If an individual method doesn't
call super then a theoretical implementation could skip the parents
methods (unless another child calls super).
All the best,
Michael Foord
Ronald
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/fuzzyman%40voidspace.org.uk
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com