[issue27576] An unexpected difference between dict and OrderedDict
Alexander Belopolsky
report at bugs.python.org
Tue Jul 19 17:01:30 EDT 2016
New submission from Alexander Belopolsky:
Consider the following code:
$ cat x.py
from collections import OrderedDict
class X:
def items(self):
print('items')
return []
def keys(self):
print('keys')
return []
print(dict(X()))
print(OrderedDict(X()))
When I run it under python 3.4, I get
$ python3.4 x.py
keys
{}
keys
OrderedDict()
but under python 3.5, I get
$ python3.5 x.py
keys
{}
items
OrderedDict()
Under 3.4 both dict and OrderedDict constructors call the keys() method of the underlying object (and then call __getitem__ repeatedly if keys() returns a non-empty list), but in 3.5 OrderedDict behavior changed and it calls the values() method instead.
----------
keywords: 3.4regression
messages: 270842
nosy: belopolsky
priority: normal
severity: normal
status: open
title: An unexpected difference between dict and OrderedDict
type: behavior
versions: Python 3.5
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue27576>
_______________________________________
More information about the Python-bugs-list
mailing list