On 13 September 2016 at 10:28, Brett Cannon <brett at 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 -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160913/5ae81ebd/attachment.html>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4