Python's super() considered super!

Duncan Booth duncan.booth at invalid.invalid
Mon May 30 05:18:26 EDT 2011


Ethan Furman <ethan at stoneleaf.us> wrote:

>>>>> foo(x=1, y=2, z=3)
>> Traceback (most recent call last):
>>   File "<pyshell#8>", line 1, in <module>
>>     foo(x=1, y=2, z=3)
>>   File "<pyshell#4>", line 2, in foo
>>     bar(y=2, **kwargs)
>> TypeError: bar() got multiple values for keyword argument 'y'
> 
> And the above error is exactly why you don't want to use named arguments 
> in MI -- because you don't know in what order the methods will be 
> called, you cannot know which named arguments to supply to the method 
> that super() will call next.
> 

No, it just means you have to be careful how you do it: if you want to pass 
'y' to a super call then you must pop it out of the arguments. This can be 
done as easily with a named argument as with an explicit 'pop()' on kwargs.

What using a named argument does it to change the default action from 
silently overwriting any argumement passing up the chain to raising an 
error if you attempt to overwrite it without first checking whether it 
exists.

-- 
Duncan Booth http://kupuguy.blogspot.com



More information about the Python-list mailing list