[Tutor] Calling method in parent class

The Green Tea Leaf thegreentealeaf at gmail.com
Tue May 12 12:39:36 CEST 2009


> If your superclass has a method with the same name (other than __init__
> here), that contains some logic that a subclass that overrides the method
> needs, it's written wrong in python. In this case, use different method
> names, or factor out the parent class methods functionality into (probably)
> a decorator. Code reuse should be strived for, but that's not the only
> purpose of inheritance. If you need to override a method in a subclass, and
> still need to call the parents method in that subclass, you're almost
> definately using inheritance wrong, with the special exception of __init__.

I think we agree on this, I can imagine that there are cases where
it's desirable to have this ... but I can't come up with a good
counter example so I assume this mean that we agree :)

> In the case of __init__, you probably want to use Parent.__init__, and not
> super, if only because of all the weird edge cases with super.

Yes, it was those edge cases that I was worried about.


-- 
The Green Tea Leaf   thegreentealeaf at gmail.com   thegreentealeaf.blogspot.com


More information about the Tutor mailing list