Commit b8b0c80f authored by Stefan Behnel's avatar Stefan Behnel

fix bug #707: optimised dict iteration over non-trivial expressions failed to...

fix bug #707: optimised dict iteration over non-trivial expressions failed to evaluate the expression

--HG--
extra : rebase_source : b2f74c2b859a2e783da3c00cb0392e41f3ea0362
parent fd7b1751
...@@ -169,7 +169,7 @@ class IterationTransform(Visitor.VisitorTransform): ...@@ -169,7 +169,7 @@ class IterationTransform(Visitor.VisitorTransform):
if reversed: if reversed:
# CPython raises an error here: not a sequence # CPython raises an error here: not a sequence
return node return node
dict_obj = function.obj dict_obj = iterator.self or function.obj
method = function.attribute method = function.attribute
is_py3 = self.module_scope.context.language_level >= 3 is_py3 = self.module_scope.context.language_level >= 3
......
...@@ -186,6 +186,29 @@ def dict_iter(dict d): ...@@ -186,6 +186,29 @@ def dict_iter(dict d):
items = [ item for item in d.items() ] items = [ item for item in d.items() ]
return keys, values, items return keys, values, items
@cython.test_assert_path_exists(
"//WhileStatNode",
"//WhileStatNode//DictIterationNextNode")
@cython.test_fail_if_path_exists(
"//ForInStatNode")
def dict_iter_new_dict():
"""
>>> dict_keys, keys, values, items = dict_iter_new_dict()
>>> sorted(dict_keys)
[11, 22, 33]
>>> sorted(keys)
[11, 22, 33]
>>> sorted(values)
[1, 2, 3]
>>> sorted(items)
[(11, 1), (22, 2), (33, 3)]
"""
dict_keys = [ key for key in {11 : 1, 22 : 2, 33 : 3} ]
keys = [ key for key in {11 : 1, 22 : 2, 33 : 3}.keys() ]
values = [ value for value in {11 : 1, 22 : 2, 33 : 3}.values() ]
items = [ item for item in {11 : 1, 22 : 2, 33 : 3}.items() ]
return dict_keys, keys, values, items
def int_literals(): def int_literals():
""" """
>>> int_literals() >>> int_literals()
......
...@@ -33,6 +33,20 @@ def iteritems(dict d): ...@@ -33,6 +33,20 @@ def iteritems(dict d):
l.sort() l.sort()
return l return l
@cython.test_assert_path_exists(
"//WhileStatNode",
"//WhileStatNode//DictIterationNextNode")
def iteritems_dict(dict d):
"""
>>> iteritems_dict(d)
[(11, 1), (12, 2), (13, 3)]
"""
l = []
for k,v in {11 : 1, 12 : 2, 13 : 3}.iteritems():
l.append((k,v))
l.sort()
return l
@cython.test_assert_path_exists( @cython.test_assert_path_exists(
"//WhileStatNode", "//WhileStatNode",
"//WhileStatNode//DictIterationNextNode") "//WhileStatNode//DictIterationNextNode")
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment