[Python-ideas] Required to call superclass __init__
Jim Jewett
jimjjewett at gmail.com
Tue Nov 13 15:36:41 CET 2007
On 11/13/07, Oleg Broytmann <phd at phd.pp.ru> wrote:
> On Tue, Nov 13, 2007 at 12:23:40AM -0700, Neil Toronto wrote:
> > I've got a working prototype metaclass and class instance
> > (require_super) and decorator (super_required).
Is this restricted to __init__ (and __new__?) or could it be used on any method?
Is there (and should there be?) a way around it, by catching the
TypeError? By creating a decoy object to call super on?
> Chicken and egg problem, in my eyes. If the user is clever enough to use
> the class and the decorator isn't she clever enough to call inherited
> __init__?
It may not be the same user.
A library or framework writer would create the base class and use the
decorator to (somewhat) ensure that subclasses meet the full interface
requirements.
A subclass writer should call the super.__init__ because it is in the
API, but Neil's metaclass makes it easier to debug if they forget.
-jJ
More information about the Python-ideas
mailing list