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
On Tue, Oct 26, 2021 at 4:32 PM Christopher Barker <[email protected]>
wrote:
> Well, you just repeated what I said, and then again asserted:
>
> On Tue, Oct 26, 2021 at 4:21 PM Chris Angelico <[email protected]> wrote:
>
>> The truth is that there is no value that can be a truly universal
>> representation of absence, so it *always* has to be specific to each
>> API.
>>
>
> But I don't see what that's the case -- why would anyone ever need to use
> a MISSING to mean anything else? If you have a different meaning, use a
> different sentinel. Sure, that wouldn't be enforceable, but it sure could
> be considered best practice.
>
> Though i suppose I'm missing something here.
>
> could it be a soft keyword?
>
> Using *a, **kw does allow us to truly omit an argument.
>>
>
> Exactly, I don't really see why this is considered important.
>
> -CHB
>
> --
> Christopher Barker, PhD (Chris)
>
> Python Language Consulting
> - Teaching
> - Scientific Software Development
> - Desktop GUI and Web Development
> - wxPython, numpy, scipy, Cython
>
--
Christopher Barker, PhD (Chris)
Python Language Consulting
- Teaching
- Scientific Software Development
- Desktop GUI and Web Development
- wxPython, numpy, scipy, Cython
_______________________________________________
Python-ideas mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at
https://mail.python.org/archives/list/[email protected]/message/VQXZD2SJATYR24MAKANCTVR56ZMYHVSG/
Code of Conduct: http://python.org/psf/codeofconduct/