Issue 23080: BoundArguments.arguments should be unordered (original) (raw)
This patch makes BoundArguments.arguments an unordered dict. As discussed on python-ideas, the rationale for this is
The current ordering in ba.arguments is the one of the parameters in the signature (which is already available via the ba.signature attribute), not the one in which the arguments are given (which will always be unavailable as long as Python doesn't keep the order of keyword arguments), so no information is lost by this patch.
The recipe in the docs for updating ba.arguments to also contain default argument values breaks that ordering, making eq behavior difficult to explain:
s = signature(lambda x=None, y=None: None) ba0 = s.bind() ba1 = s.bind(x=None) ba2 = s.bind(y=None)
At that point, with the current implementation, we'll have ba0 == ba1 != ba2... why?
- Implementing ba.arguments as a regular dict makes signature.bind much faster, which is important e.g. if it is used in a decorating type-checker as suggested in PEP362. (That specific issue could also be improved by a C-implemented OrderedDict, but the other reasons remain valid.)