]> granicus.if.org Git - python/commitdiff
return views from dict proxy items/values/keys #10630
authorBenjamin Peterson <benjamin@python.org>
Tue, 7 Dec 2010 03:46:27 +0000 (03:46 +0000)
committerBenjamin Peterson <benjamin@python.org>
Tue, 7 Dec 2010 03:46:27 +0000 (03:46 +0000)
Lib/test/test_descr.py
Objects/descrobject.c

index 932214d692cbab2430a957cf90bd940122adea0e..233b7cb0ac7a17f51a751b6bdb99cbbc51f70967 100644 (file)
@@ -4233,20 +4233,26 @@ class DictProxyTests(unittest.TestCase):
         self.C = C
 
     def test_iter_keys(self):
-        # Testing dict-proxy iterkeys...
-        keys = [ key for key in self.C.__dict__.keys() ]
+        # Testing dict-proxy keys...
+        it = self.C.__dict__.keys()
+        self.assertNotIsInstance(it, list)
+        keys = list(it)
         keys.sort()
         self.assertEqual(keys, ['__dict__', '__doc__', '__module__',
             '__weakref__', 'meth'])
 
     def test_iter_values(self):
-        # Testing dict-proxy itervalues...
-        values = [ values for values in self.C.__dict__.values() ]
+        # Testing dict-proxy values...
+        it = self.C.__dict__.values()
+        self.assertNotIsInstance(it, list)
+        values = list(it)
         self.assertEqual(len(values), 5)
 
     def test_iter_items(self):
         # Testing dict-proxy iteritems...
-        keys = [ key for (key, value) in self.C.__dict__.items() ]
+        it = self.C.__dict__.items()
+        self.assertNotIsInstance(it, list)
+        keys = [item[0] for item in it]
         keys.sort()
         self.assertEqual(keys, ['__dict__', '__doc__', '__module__',
             '__weakref__', 'meth'])
index 11418d19e57bbf62c31bbcf07db8449e1a80cd46..de065b433187682d9c7dbd19d52e615b518cca9b 100644 (file)
@@ -710,19 +710,19 @@ proxy_get(proxyobject *pp, PyObject *args)
 static PyObject *
 proxy_keys(proxyobject *pp)
 {
-    return PyMapping_Keys(pp->dict);
+    return PyObject_CallMethod(pp->dict, "keys", NULL);
 }
 
 static PyObject *
 proxy_values(proxyobject *pp)
 {
-    return PyMapping_Values(pp->dict);
+    return PyObject_CallMethod(pp->dict, "values", NULL);
 }
 
 static PyObject *
 proxy_items(proxyobject *pp)
 {
-    return PyMapping_Items(pp->dict);
+    return PyObject_CallMethod(pp->dict, "items", NULL);
 }
 
 static PyObject *