Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-14 Thread Eric Snow
On Nov 7, 2017 08:12, "INADA Naoki" wrote: Additionally, class namespace should keep insertion order. It's language spec from 3.6. So we should have two mode for such optimization. It makes dict more complicated. FWIW, PEP 520 (Preserving Class Attribute Definition

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-14 Thread Armin Rigo
Hi Antoine, On 8 November 2017 at 10:28, Antoine Pitrou wrote: > Yet, PyPy has no reference counting, and it doesn't seem to be a cause > of concern. Broken code is fixed along the way, when people notice. It is a major cause of concern. This is the main blocker for

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-09 Thread Nathaniel Smith
On Thu, Nov 9, 2017 at 1:46 PM, Cameron Simpson wrote: > On 08Nov2017 10:28, Antoine Pitrou wrote: >> >> On Wed, 8 Nov 2017 13:07:12 +1000 >> Nick Coghlan wrote: >>> >>> On 8 November 2017 at 07:19, Evpok Padding

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-09 Thread Cameron Simpson
On 08Nov2017 10:28, Antoine Pitrou wrote: On Wed, 8 Nov 2017 13:07:12 +1000 Nick Coghlan wrote: On 8 November 2017 at 07:19, Evpok Padding wrote: > On 7 November 2017 at 21:47, Chris Barker wrote: >> if

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-08 Thread Antoine Pitrou
On Wed, 8 Nov 2017 13:07:12 +1000 Nick Coghlan wrote: > On 8 November 2017 at 07:19, Evpok Padding wrote: > > On 7 November 2017 at 21:47, Chris Barker wrote: > >> if dict order is preserved in cPython , people WILL count on

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Guido van Rossum
I'll probably get complaints because I'm not waiting for the benchmark results to come in, but I think I've seen enough. To me the only defensible behavior *other than the pre-3.6 behavior* is that after deletions the order remains preserved and new insertions happen at the end -- i.e. the same

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Steven D'Aprano
On Tue, Nov 07, 2017 at 05:37:15PM +0200, Serhiy Storchaka wrote: > 07.11.17 16:56, Steven D'Aprano пише: > >To clarify: if we start with an empty dict, add keys A...D, delete B, > >then add E...H, we could expect: [...] > Rather > > {A: 1, D: 4, C: 3} # move the last item in place of removed >

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Random832
On Tue, Nov 7, 2017, at 09:56, Steven D'Aprano wrote: > Don't let the perfect be the enemy of the good. > > For many applications, keys are never removed from the dict, so this > doesn't matter. If you never delete a key, then the remaining keys will > never be reordered. > > I think that

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Nick Coghlan
On 8 November 2017 at 07:19, Evpok Padding wrote: > On 7 November 2017 at 21:47, Chris Barker wrote: >> if dict order is preserved in cPython , people WILL count on it! > > I won't, and if people do and their code break, they'll have only

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Evpok Padding
On 7 November 2017 at 21:47, Chris Barker wrote: > On Tue, Nov 7, 2017 at 11:50 AM, Tim Peters wrote: > >> Is it worth guaranteeing that will always "work" (as intended)? Not >> to me, but I do have code that relies on it now - > > > This is

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Chris Barker
On Tue, Nov 7, 2017 at 11:50 AM, Tim Peters wrote: > Is it worth guaranteeing that will always "work" (as intended)? Not > to me, but I do have code that relies on it now - This is critically important -- no one looks at the language spec to figure out how something

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Tim Peters
[Peter Ludemann] > Does it matter whether the dict order after pop/delete is explicitly > specified, or just specified that it's deterministic? Any behavior whatsoever becomes essential after it becomes known ;-) For example, dicts as currently ordered easily support LRU (least recently used)

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Barry Warsaw
Antoine Pitrou wrote: > Well... It really depends what kind of problem you're solving. I > certainly delete or pop items from dicts quite often. > > Let's not claim that deleting items from a dict is a rare or advanced > feature. It is not. +1. It's a pretty common pattern for handling

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Peter Ludemann via Python-Dev
Does it matter whether the dict order after pop/delete is explicitly specified, or just specified that it's deterministic? On 7 November 2017 at 11:28, Antoine Pitrou wrote: > On Wed, 8 Nov 2017 06:19:46 +1100 > Chris Angelico wrote: > > > > I've used a

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Antoine Pitrou
On Wed, 8 Nov 2017 06:19:46 +1100 Chris Angelico wrote: > > I've used a good few dictionary objects in my time, but most of them > have literally never had any items deleted from them. Well... It really depends what kind of problem you're solving. I certainly delete or pop

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Chris Angelico
On Wed, Nov 8, 2017 at 1:32 AM, Antoine Pitrou wrote: > On Wed, 8 Nov 2017 00:01:04 +1000 > Nick Coghlan wrote: > >> On 7 November 2017 at 23:48, Stefan Krah wrote: >> > >> > >> > This is just a reminder that the current dict is not

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Barry Warsaw
On Nov 7, 2017, at 07:12, Antoine Pitrou wrote: > The problem is this is taking things to a level of precision that makes > the guarantee tedious to remember and reason about. > > The only thing that's friendly to (non-expert) users is either "dicts > are always ordered [by

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread INADA Naoki
>> > If further guarantees are proposed, perhaps it would be a good idea to >> > open a new thread and state what exactly is being proposed. >> >> "Insertion ordered until the first key removal" is the only guarantee >> that's being proposed. > > Is it? It seems to me that many arguments being

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Serhiy Storchaka
07.11.17 16:56, Steven D'Aprano пише: To clarify: if we start with an empty dict, add keys A...D, delete B, then add E...H, we could expect: {A: 1} {A: 1, B: 2} {A: 1, B: 2, C: 3} {A: 1, B: 2, C: 3, D: 4} {D: 4, A: 1, C: 3} # some arbitrary reordering {D: 4, A: 1, C: 3, E: 5} {D: 4, A: 1, C:

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Antoine Pitrou
On Tue, 7 Nov 2017 09:44:07 -0500 Yury Selivanov wrote: > > One common pattern that I see frequently is this: > > def foo(**kwargs): > kwargs.pop('somekey', None) > bar(**kwargs) I see it frequently too, but that's in code meant to be Python

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Antoine Pitrou
On Wed, 8 Nov 2017 01:56:42 +1100 Steven D'Aprano wrote: > > I think that Nick's intent was not to say that after a single deletion, > the ordering guarantee goes away "forever", but that a deletion may be > permitted to reorder the keys, after which further additions will

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Steven D'Aprano
On Tue, Nov 07, 2017 at 03:32:29PM +0100, Antoine Pitrou wrote: [...] > > "Insertion ordered until the first key removal" is the only guarantee > > that's being proposed. > > Is it? It seems to me that many arguments being made are only relevant > under the hypothesis that insertion is ordered

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Yury Selivanov
On Tue, Nov 7, 2017 at 9:32 AM, Antoine Pitrou wrote: > On Wed, 8 Nov 2017 00:01:04 +1000 > Nick Coghlan wrote: > >> On 7 November 2017 at 23:48, Stefan Krah wrote: >> > >> > >> > This is just a reminder that the current dict is not

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Antoine Pitrou
On Wed, 8 Nov 2017 00:01:04 +1000 Nick Coghlan wrote: > On 7 November 2017 at 23:48, Stefan Krah wrote: > > > > > > This is just a reminder that the current dict is not an "OrderedDict": > > > from collections import OrderedDict >

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Stefan Krah
On Wed, Nov 08, 2017 at 12:01:04AM +1000, Nick Coghlan wrote: > > The recent proposal was primarily about guaranteeing the insertion order of > > dict literals. > > > > If further guarantees are proposed, perhaps it would be a good idea to > > open a new thread and state what exactly is being

Re: [Python-Dev] The current dict is not an "OrderedDict"

2017-11-07 Thread Nick Coghlan
On 7 November 2017 at 23:48, Stefan Krah wrote: > > > This is just a reminder that the current dict is not an "OrderedDict": > from collections import OrderedDict OrderedDict(a=0, b=1) == OrderedDict(b=1, a=0) > False dict(a=0, b=1) == dict(b=1, a=0) > True > >