On 13 September 2016 at 10:28, Brett Cannon <br...@python.org> wrote:
> >> I'd like to add one more documented constraint - that dict literals >> maintain definition order (so long as the dict is not further modified). >> This allows defining a dict literal and then passing it as **kwargs. >> > > That would require all dictionaries keep their insertion order which we > are explicitly not doing (at least yet). If you look at the PEPs that are > asking for definition order they specify an "ordered mapping", not a dict. > Making dict literals do this means dict literals become "order mapping > literals" which isn't what they are; they are dict literals. I don't think > we should extend this guarantee to literals any more than any other > dictionary. > I'm not sure I agree with you, but I'm not going to argue too strongly either (it can always be revisited later). I will note that a conforming implementation could be that the result of evaluating a dict literal is a frozen ordered dict which transparently changes to be a mutable dict as required. There could well be performance and/or memory benefits from such a dict implementation. Personally I expect all Python 3.6 implementations will have order-preserving dict as that's the easiest way to achieve the existing guarantees. And that enough code will come to depend on an order-preserving dict that eventually the decision will be made to retrospectively guarantee the semantics. Tim Delaney
_______________________________________________ Python-Dev mailing list Python-Dev@python.org https://mail.python.org/mailman/listinfo/python-dev Unsubscribe: https://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com