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

Erik python at lucidity.plus.com
Sat Apr 29 21:30:12 EDT 2017


On 30/04/17 01:17, breamoreboy at 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 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

OK, so technically it is a subclass, I didn't notice that, but where 
does the documentation explain all of the differences in behaviour? It 
doesn't. It states "it's a subclass of dict that does <this> and <that>" 
(by which I mean "order the keys") and it's not unreasonable to 
therefore believe that's _all_ it does differently. If if it actually 
does "<this>, <that>, <the other>, <something>, <foo>" (by which I mean 
"order the keys and implement very different behavior for other methods 
such as __init__ and __update__") then the documentation is lacking 
(because it doesn't mention it). Isn't that what I said?

E.



More information about the Python-list mailing list