[Python-ideas] Delegating `BoundArguments.__getitem__` to `BoundArguments.arguments.__getitem__`

Yury Selivanov yselivanov.ml at gmail.com
Fri Oct 3 23:34:20 CEST 2014


Hi,


On 2014-10-03, 12:51 PM, Ram Rachum wrote:
> And while we're at it, if the user tries to access an argument that isn't
> given but has a default, let's return the default.

No. There is a note on this in python docs re BoundArguments.arguments:
"Contains only explicitly bound arguments."

This is an important feature, because it gives you information of what 
exact set of arguments was bound in the first place. Also, when you use 
BoundArguments for RPC, you're interested in passing the minimal set of 
information for each call.

If you want to change this behaviour, you're free to extend Signature 
class and return a customized BA instance. In 3.5 there is 
Signature.from_callable for making this easy, and there is a 3 line 
example in docs on how to bind defaults.
>
> On Fri, Oct 3, 2014 at 7:30 PM, Ram Rachum <ram at rachum.com> wrote:
>
>> Hi,
>>
>> I suggest delegating `BoundArguments.__getitem__` to
>> `BoundArguments.arguments.__getitem__`, so instead of doing
>> `bound_arguments.arguments['foo']` we could do `bound_arguments['foo']`.

You'll also need to delegate __setitem__, keys(), __len__ and all other 
Mapping methods. And to be honest, I see absolutely no point in doing this.

>> Since there isn't that much more to a `BoundArguments` object than its
>> arguments

For now yes. In future we might want to extend the API.

Yury


More information about the Python-ideas mailing list