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

breamoreboy at gmail.com breamoreboy at gmail.com
Sat Apr 29 20:17:56 EDT 2017


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__,
> > __iter__, and __len__.
> 
> Or, I could derive from collections.OrderedDict and just implement the 
> two methods that I actually want to change the behavior of (did you read 
> the rest of my post?) ;)
> 
> 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 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 me.

C:\python                                                  
Python 3.6.1 (v3.6.1:69c0db5, Mar 21 2017, 18:41:36) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> from collections import OrderedDict
>>> o = OrderedDict()
>>> isinstance(o, dict)
True

Kindest regards.

Mark Lawrence.


More information about the Python-list mailing list