[Python-Dev] Python 3.6 dict becomes compact and gets a private version; and keywords become ordered (original) (raw)

Brett Cannon brett at python.org
Mon Sep 12 20:28:00 EDT 2016


On Mon, 12 Sep 2016 at 16:52 Tim Delaney <timothy.c.delaney at gmail.com> wrote:

On 10 September 2016 at 03:17, Guido van Rossum <guido at python.org> wrote:

I've been asked about this. Here's my opinion on the letter of the law in 3.6:

- keyword args are ordered - the namespace passed to a metaclass is ordered by definition order - ditto for the class dict A compliant implementation may ensure the above three requirements either by making all dicts ordered, or by providing a custom dict subclass (e.g. OrderedDict) in those three cases. 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.

Hmm - again, there's no mention of dict literals in the PEPs. I'm assuming that dict literals will preserve their definition order with the new implementation, but is that a valid assumption? Guess I can test it now 3.6.0b1 is out.

They will as an implementation detail, not because the language spec requires it. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20160913/167f4658/attachment.html>



More information about the Python-Dev mailing list