[Python-ideas] Required to call superclass __init__

Scott Dial scott+python-ideas at scottdial.com
Thu Nov 15 09:14:25 CET 2007

Jim Jewett wrote:
> I don't yet
> see what those simplifications should actually be, but maybe someone
> else will if you publish and wait long enough.

The first thing I noticed was that the naming scheme is confusing. 
Between required_super and super_required, neither of them indicate to 
me which is the function decorator and which is the base class. 
Furthermore, I don't see why required_super (the base class) needs a 
distinct name. Perhaps I am being a bit to clever, but couldn't we just 
overload the __new__ method of the base class.

def _super_required(func):

class super_required(object):
     def __new__(cls, *func):
         if len(func) > 0:
             return _super_required(*func)
         return object.__new__(cls)

Leaving your example now being spelled as:

class A(super_required):
     def __init__(self):

I can't think of a case that the the base class would ever be passed 
arguments, so this seems ok and rids us of the naming oddities.


Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu

More information about the Python-ideas mailing list