summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2010-12-07 03:46:27 (GMT)
committerBenjamin Peterson <benjamin@python.org>2010-12-07 03:46:27 (GMT)
commit0eb7f86320c13648f41e6a39b47b01d774ea117f (patch)
tree874eddae1c3a45c6fe75f3d434641765cbf3841c
parentb5d793309e6c0752420f10081d1812bced53539b (diff)
downloadcpython-0eb7f86320c13648f41e6a39b47b01d774ea117f.zip
cpython-0eb7f86320c13648f41e6a39b47b01d774ea117f.tar.gz
cpython-0eb7f86320c13648f41e6a39b47b01d774ea117f.tar.bz2
return views from dict proxy items/values/keys #10630
-rw-r--r--Lib/test/test_descr.py16
-rw-r--r--Objects/descrobject.c6
2 files changed, 14 insertions, 8 deletions
diff --git a/Lib/test/test_descr.py b/Lib/test/test_descr.py
index 932214d..233b7cb 100644
--- a/Lib/test/test_descr.py
+++ b/Lib/test/test_descr.py
@@ -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'])
diff --git a/Objects/descrobject.c b/Objects/descrobject.c
index 11418d1..de065b4 100644
--- a/Objects/descrobject.c
+++ b/Objects/descrobject.c
@@ -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 *