Author Rhamphoryncus
Recipients
Date 2007-03-22.00:44:29
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
I think the avoidance of super() is largely *because* of this kind of leniency.  Consider this snippet on python 2.3:

class Base(object):
    def __init__(self, foo=None, *args, **kwargs):
        super(Base, self).__init__(foo, *args, **kwargs)
Base(foo='bar')
Base('bar', 42)
Base('bar', 42, x=7)

All pass silently, no error checking.  Now consider a python 3.0 version, with a strict object.__init__:

class Base:
    def __init__(self, foo=None, *, y='hi', **kwargs):
        super(Base, self).__init__(**kwargs)
Base(foo='bar')  # Valid, accepted
Base('bar', 42)  # Raises exception
Base('bar', x=7)  # Raises exception

The error checking added by this bug/patch and the error checking added by PEP 3102 (keyword-only arguments) make super a lot more sane.

I think it would also help if calling a method via super() didn't allow positional arguments.  If the base class's arguments can't be given as keyword args then you probably should call it explicitly, rather than relying on super()'s MRO.

I was also going to suggest super() should automagically create empty methods your parent classes don't have, but then I realized you really should have a base class that asserts the lack of such an automagic method:

class Base(object):
    def mymethod(self, myonlyarg='hello world'):
        assert not hasattr(super(Base, self), 'mymethod')

By the time you reach this base class you will have stripped off any extra arguments that your subclasses added, leaving you with nothing to pass up (and nothing to pass to).  Having two mixins with the same method name and without a common parent class is just not sane.
History
Date User Action Args
2007-08-23 14:52:36adminlinkissue1683368 messages
2007-08-23 14:52:36admincreate