Commit 23b3fda7 authored by Stefan Behnel's avatar Stefan Behnel

transform empty comprehensions into empty literals

parent 469db401
......@@ -3233,6 +3233,13 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
return base
return node
def visit_ComprehensionNode(self, node):
self.visitchildren(node)
if isinstance(node.loop, Nodes.StatListNode) and not node.loop.stats:
# loop was pruned already => transform into literal
return node.target
return node
def visit_ForInStatNode(self, node):
self.visitchildren(node)
sequence = node.iterator.sequence
......
......@@ -213,10 +213,11 @@ def for_in_empty_else():
@cython.test_fail_if_path_exists(
"//ComprehensionNode",
"//ForInStatNode",
)
@cython.test_assert_path_exists(
"//ComprehensionNode",
"//ListNode",
)
def for_in_empty_listcomp():
"""
......@@ -227,10 +228,11 @@ def for_in_empty_listcomp():
@cython.test_fail_if_path_exists(
"//ComprehensionNode",
"//ForInStatNode",
)
@cython.test_assert_path_exists(
"//ComprehensionNode",
"//ListNode",
)
def for_in_empty_nested_listcomp():
"""
......@@ -242,7 +244,7 @@ def for_in_empty_nested_listcomp():
@cython.test_fail_if_path_exists(
"//ForInStatNode//ForInStatNode",
)
)
@cython.test_assert_path_exists(
"//ForInStatNode",
"//ComprehensionNode",
......
......@@ -83,10 +83,11 @@ def unicode_slicing_safe_surrogates2():
@cython.test_fail_if_path_exists(
"//ComprehensionNode",
"//ForInStatNode",
)
@cython.test_assert_path_exists(
"//ComprehensionNode",
"//SetNode",
)
def for_in_empty_setcomp():
"""
......
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