[Python-Dev] Guarantee ordered dict literals in v3.7?

Antoine Pitrou solipsis at pitrou.net
Sun Nov 5 15:18:24 EST 2017


On Sun, 5 Nov 2017 21:06:12 +0100
Stefan Krah <stefan at bytereef.org> wrote:

> On Sun, Nov 05, 2017 at 09:35:38PM +0200, Serhiy Storchaka wrote:
> > 05.11.17 21:20, Stefan Krah пише:  
> > >On Sun, Nov 05, 2017 at 09:01:40PM +0200, Serhiy Storchaka wrote:  
> > >>Do you suggest to make dictionary displays producing OrderedDict
> > >>instead of dict?  
> > >
> > >No, this is essentially a language spec doc issue that would guarantee
> > >the ordering properties of the current dict implementation.  
> > 
> > Wouldn't be enough to guarantee just the ordering of dicts before
> > first deletion? Or before first resizing (the maximal size of
> > dictionary displays is known at compile time, so they can be
> > presized)?  
> 
> Yes, for my use case that would be sufficient and that's what
> I had in mind initially.
> 
> 
> A luxury syntax addition like {a = 10, b = {c = "foo"}} that is read
> as an OrderedDict (where the keys a, b, c are implicitly strings) would
> of course also be sufficient for my use case.

Or you are ok with:

  OD = OrderedDict
  # ...
  OD(a=10, b=OD(c="foo"))

Regards

Antoine.




More information about the Python-Dev mailing list