Author: Carl Friedrich Bolz <[email protected]>
Branch:
Changeset: r73760:d6577a460c28
Date: 2014-10-02 16:49 +0200
http://bitbucket.org/pypy/pypy/changeset/d6577a460c28/
Log: implement list(dct) by just calling the .keys() method
diff --git a/rpython/rtyper/lltypesystem/rdict.py
b/rpython/rtyper/lltypesystem/rdict.py
--- a/rpython/rtyper/lltypesystem/rdict.py
+++ b/rpython/rtyper/lltypesystem/rdict.py
@@ -308,6 +308,9 @@
def rtype_method_items(self, hop):
return self._rtype_method_kvi(hop, ll_dict_items)
+ def rtype_bltn_list(self, hop):
+ return self._rtype_method_kvi(hop, ll_dict_keys)
+
def rtype_method_iterkeys(self, hop):
hop.exception_cannot_occur()
return DictIteratorRepr(self, "keys").newiter(hop)
diff --git a/rpython/rtyper/test/test_rdict.py
b/rpython/rtyper/test/test_rdict.py
--- a/rpython/rtyper/test/test_rdict.py
+++ b/rpython/rtyper/test/test_rdict.py
@@ -242,6 +242,16 @@
res = self.interpret(func, ())#, view=True)
assert res == 14
+ def test_list_dict(self):
+ def func():
+ dic = self.newdict()
+ dic[' 4'] = 1000
+ dic[' 8'] = 200
+ keys = list(dic)
+ return ord(keys[0][1]) + ord(keys[1][1]) - 2*ord('0') + len(keys)
+ res = self.interpret(func, ())#, view=True)
+ assert res == 14
+
def test_dict_inst_keys(self):
class Empty:
pass
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit