[pypy-commit] pypy py3.5: OrderedDict needs the custom classes for keys()/values()/items(),
arigo
pypy.commits at gmail.com
Mon Feb 6 14:09:38 EST 2017
Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r89985:f305eb5d13c2
Date: 2017-02-06 20:08 +0100
http://bitbucket.org/pypy/pypy/changeset/f305eb5d13c2/
Log: OrderedDict needs the custom classes for keys()/values()/items(),
for reversed() to work on them
diff --git a/lib_pypy/_pypy_collections.py b/lib_pypy/_pypy_collections.py
--- a/lib_pypy/_pypy_collections.py
+++ b/lib_pypy/_pypy_collections.py
@@ -68,3 +68,30 @@
return dict.__eq__(self, other)
__ne__ = object.__ne__
+
+ def keys(self):
+ "D.keys() -> a set-like object providing a view on D's keys"
+ return _OrderedDictKeysView(self)
+
+ def items(self):
+ "D.items() -> a set-like object providing a view on D's items"
+ return _OrderedDictItemsView(self)
+
+ def values(self):
+ "D.values() -> an object providing a view on D's values"
+ return _OrderedDictValuesView(self)
+
+
+class _OrderedDictKeysView(KeysView):
+ def __reversed__(self):
+ yield from reversed_dict(self._mapping)
+
+class _OrderedDictItemsView(ItemsView):
+ def __reversed__(self):
+ for key in reversed_dict(self._mapping):
+ yield (key, self._mapping[key])
+
+class _OrderedDictValuesView(ValuesView):
+ def __reversed__(self):
+ for key in reversed_dict(self._mapping):
+ yield self._mapping[key]
More information about the pypy-commit
mailing list