subclassing and defaults.
There is one use case I'm not sure how to wrap my head around.
Say a class and subclass have different default arguments. And we want to pass the fact that the argument wasn't set along to the superclass. The "use None" convention works fine:
def __init__(self, something=None):
super().__init__(something)
The superclass could define its own default.
But deferred binding would not work:
def __init__(self, something=an_expression):
super().__init__(something)
The superclass would get the result of an_expression, and not know that it should use its default.
Is this an actual problem? I'm not sure -- I can't think of when I wouldn't want a subclass to override the default of the superclass, but maybe ? And of course, if you really do need that, then use a sentinel in that case :-) No one's suggesting that every default should be specified explicitly!
-CHB
Christopher Barker, PhD (Chris)
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython