Author: Armin Rigo <ar...@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]
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to