Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Gregory Ewing
Erik wrote: Is there not a class that is somewhere between "dict" and "OrderedDict" that provides what I need? Such a class could exist, but the stdlib doesn't happen to provide one as far as I know. Note, though, that you're relying on implementation details of OrderedDict when you use it to

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread breamoreboy
On Sunday, April 30, 2017 at 2:30:25 AM UTC+1, Erik wrote: > On 30/04/17 01:17, breamoreboy wrote: > > On Sunday, April 30, 2017 at 12:23:19 AM UTC+1, Erik wrote: > >> The other is that the documentation of collections.OrderedDict seems to > >> be lacking (it is talking in terms of being a "dict" s

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Erik
On 30/04/17 01:17, breamore...@gmail.com wrote: On Sunday, April 30, 2017 at 12:23:19 AM UTC+1, Erik wrote: The other is that the documentation of collections.OrderedDict seems to be lacking (it is talking in terms of being a "dict" subclass, but it actually isn't one). E. Could have fooled m

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Erik
On 30/04/17 01:31, Ben Finney wrote: Erik writes: On 29/04/17 23:40, Ned Batchelder wrote: For creating your own class that acts like a dict, you should derive from collections.abc.MutableMapping, which only requires implementing __getitem__, __setitem__, __delitem__, __iter__, and __len__.

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread breamoreboy
On Sunday, April 30, 2017 at 12:23:19 AM UTC+1, Erik wrote: > On 29/04/17 23:40, Ned Batchelder wrote: > > For creating your own class that acts like > > a dict, you should derive from collections.abc.MutableMapping, which > > only requires implementing __getitem__, __setitem__, __delitem__, > > __

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Ben Finney
Erik writes: > On 29/04/17 23:40, Ned Batchelder wrote: > > For creating your own class that acts like a dict, you should derive > > from collections.abc.MutableMapping, which only requires > > implementing __getitem__, __setitem__, __delitem__, __iter__, and > > __len__. > > Or, I could derive f

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Gregory Ewing
Erik wrote: That's one of the points I'm trying to make - why is it harder than it needs to be to do something this simple? The built-in dict class is used internally to implement various namespaces (module, class, instance, etc.), so it needs to be extremely efficient. Funnelling all updates t

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Erik
On 29/04/17 23:40, Ned Batchelder wrote: For creating your own class that acts like a dict, you should derive from collections.abc.MutableMapping, which only requires implementing __getitem__, __setitem__, __delitem__, __iter__, and __len__. Or, I could derive from collections.OrderedDict and j

Re: Inconsistency between dict() and collections.OrderedDict() methods.

2017-04-29 Thread Ned Batchelder
On Saturday, April 29, 2017 at 4:20:06 PM UTC-4, Erik wrote: > It seems a little onerous that I have to put the key checks in several > places and implement each of those APIs manually again (and keep on top > of that if dict() grows some new methods that involve setting items). Is > there a co