[Python-ideas] Why does BoundArguments use an OrderedDict?

Nick Coghlan ncoghlan at gmail.com
Thu Dec 18 08:05:57 CET 2014


On 18 December 2014 at 12:57, Guido van Rossum <guido at python.org> wrote:
> On Wed, Dec 17, 2014 at 6:15 PM, Antony Lee <antony.lee at berkeley.edu> wrote:
>>
>> The discussion has drifted towards improving OrderedDict (something I
>> certainly approve), but the semantic question is still there: why should
>> BoundArguments.arguments be ordered by the parameter order?  For example,
>> the recipe just below in the docs, for filling in the remaining default
>> arguments, breaks that ordering, without even mentioning that.
>
>
> Given that the answer hasn't been answered yet, perhaps nobody remembers the
> reason any more. But why does it bother you so much? In my experience the
> inspect module wasn't written for performance but for functionality. If it
> really hurts your ability to do something that you need to be fast, perhaps
> you can supply a patch? Make sure to run the tests and update the docs as
> needed.

As far as I'm aware, it's an ordered dictionary because that makes the
default repr() predictable when binding arguments for a given function
(in the absence of after-the-fact manipulation like the example in the
docs that injects the default values as explicitly bound arguments).

The inspect.signature() machinery includes quite a few things like
that where the serialisation as a human readable string is considered
as important then the programmatic representation.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list