[pypy-commit] pypy py3.6: call .keys first on the argument to OrderedDict
cfbolz
pypy.commits at gmail.com
Wed Feb 20 17:42:43 EST 2019
Author: Carl Friedrich Bolz-Tereick <cfbolz at gmx.de>
Branch: py3.6
Changeset: r96119:068ea0e91377
Date: 2019-02-20 22:44 +0100
http://bitbucket.org/pypy/pypy/changeset/068ea0e91377/
Log: call .keys first on the argument to OrderedDict
diff --git a/pypy/module/_collections/app_odict.py b/pypy/module/_collections/app_odict.py
--- a/pypy/module/_collections/app_odict.py
+++ b/pypy/module/_collections/app_odict.py
@@ -43,12 +43,12 @@
len(args))
if args:
other = args[0]
- if hasattr(other, 'items'):
+ if hasattr(other, "keys"):
+ for key in other.keys():
+ self[key] = other[key]
+ elif hasattr(other, 'items'):
for key, value in other.items():
self[key] = value
- elif hasattr(other, "keys"):
- for key in other.keys():
- self[key] = other[key]
else:
for key, value in other:
self[key] = value
diff --git a/pypy/module/_collections/test/test_ordereddict.py b/pypy/module/_collections/test/test_ordereddict.py
--- a/pypy/module/_collections/test/test_ordereddict.py
+++ b/pypy/module/_collections/test/test_ordereddict.py
@@ -36,3 +36,18 @@
assert list(reversed(od.keys())) == [t[0] for t in reversed(pairs)]
assert list(reversed(od.values())) == [t[1] for t in reversed(pairs)]
assert list(reversed(od.items())) == list(reversed(pairs))
+
+ def test_call_key_first(self):
+ from _collections import OrderedDict
+
+ calls = []
+ class Spam:
+ def keys(self):
+ calls.append('keys')
+ return ()
+ def items(self):
+ calls.append('items')
+ return ()
+
+ OrderedDict(Spam())
+ assert calls == ['keys']
More information about the pypy-commit
mailing list