[Python-ideas] deferred default arguments
Terry Reedy
tjreedy at udel.edu
Thu Jul 14 06:58:54 CEST 2011
On 7/13/2011 6:43 PM, Eric Snow wrote:
> On Wed, Jul 13, 2011 at 3:36 PM, Terry Reedy<tjreedy at udel.edu> wrote:
>> On 7/13/2011 3:26 PM, Eric Snow wrote:
>>
>>> class X:
>>> def f(self, name="N/A"):
>>
>> print(name)
>>>
>>> class Y(X):
>>> def f(self, name="N/A"):
>>> super().f(name)
>>
>> I believe
>>
>> class Y(X):
>> def f(self, name=None):
>> super().f(name)
>> f.__defaults__ = X.f.__defaults__
>>
>> will more or less do what you want. Using 'super()' instead of 'X' does not
>> seem to work. The default replacement might be done with a function or class
>> decorator.
>
> Yeah, but if the defaults of X.f get changed at runtime,
That would be *extremely* unusual. I was not sure __defaults__ was
writable until I tried it.
--
Terry Jan Reedy
More information about the Python-ideas
mailing list