summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2015-05-30 17:43:36 (GMT)
committerEric Snow <ericsnowcurrently@gmail.com>2015-05-30 17:43:36 (GMT)
commit67fb92e8c690ccb0d3a557affcc6b46c13cb94b0 (patch)
treefa2117381c4e9e7f826f5bc2379fd4ee2f39b163
parentc5e59609ac9947e91e7c2633c1e3634ff766ab08 (diff)
downloadcpython-67fb92e8c690ccb0d3a557affcc6b46c13cb94b0.zip
cpython-67fb92e8c690ccb0d3a557affcc6b46c13cb94b0.tar.gz
cpython-67fb92e8c690ccb0d3a557affcc6b46c13cb94b0.tar.bz2
Issue #16991: Do not return None from OrderedDict.__reversed__.
-rw-r--r--Lib/test/test_collections.py14
-rw-r--r--Objects/odictobject.c3
2 files changed, 13 insertions, 4 deletions
diff --git a/Lib/test/test_collections.py b/Lib/test/test_collections.py
index 3bb326a..3f02129 100644
--- a/Lib/test/test_collections.py
+++ b/Lib/test/test_collections.py
@@ -1773,6 +1773,19 @@ class OrderedDictTests:
self.assertEqual(sorted(reversed(od)),
sorted([t[0] for t in reversed(pairs)]))
+ def test_iterators_empty(self):
+ OrderedDict = self.module.OrderedDict
+ od = OrderedDict()
+ empty = []
+ self.assertEqual(list(od), empty)
+ self.assertEqual(list(od.keys()), empty)
+ self.assertEqual(list(od.values()), empty)
+ self.assertEqual(list(od.items()), empty)
+ self.assertEqual(list(reversed(od)), empty)
+ self.assertEqual(list(reversed(od.keys())), empty)
+ self.assertEqual(list(reversed(od.values())), empty)
+ self.assertEqual(list(reversed(od.items())), empty)
+
def test_popitem(self):
OrderedDict = self.module.OrderedDict
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
@@ -1965,7 +1978,6 @@ class OrderedDictTests:
od = OrderedDict(**d)
self.assertGreater(sys.getsizeof(od), sys.getsizeof(d))
- OrderedDict = self.module.OrderedDict
def test_override_update(self):
OrderedDict = self.module.OrderedDict
# Verify that subclasses can override update() without breaking __init__()
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index a5fecab..cc6c53c 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -1357,9 +1357,6 @@ static PyObject * odictiter_new(PyODictObject *, int);
static PyObject *
odict_reversed(PyODictObject *od)
{
- if (_odict_EMPTY(od)) {
- Py_RETURN_NONE;
- }
return odictiter_new(od, _odict_ITER_KEYS|_odict_ITER_REVERSED);
}