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

Petr Viktorin encukou at gmail.com
Fri Dec 19 10:07:58 CET 2014

On Thu, Dec 18, 2014 at 9:18 PM, Tim Delaney
<timothy.c.delaney at gmail.com> wrote:
> On 19 December 2014 at 03:09, <random832 at fastmail.us> wrote:
>> On Thu, Dec 18, 2014, at 02:05, Nick Coghlan wrote:
>> > 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.
>> Would it be reasonable to make a lightweight "predictable dict" class
>> that makes a weaker guarantee, e.g. that the enumeration order will
>> match the insertion order in the case where it is filled from empty with
>> no intervening deletions and not guaranteed in any other cases?

I believe that if there's a new predictabledict type, and deleting
from it would invalidate the order, then predictabledict should not
support deletions.
Perhaps it should be all-out immutable to prevent surprises.
It would break backwards compatibility if that was used for **kwargs, though.

> My understanding is that Raymond's alternative dict implementation works
> exactly like this, and is noted as an alternative for PEP 468:
> https://www.python.org/dev/peps/pep-0468/ .
> Discussion starts at:
> https://mail.python.org/pipermail/python-dev/2012-December/123028.html

More information about the Python-ideas mailing list