Commit 5b182356 authored by Stefan Behnel's avatar Stefan Behnel

use standard node dispatch mechanism instead of explicit type tests in transform

parent 3b1277a7
...@@ -3952,6 +3952,12 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): ...@@ -3952,6 +3952,12 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
sequence_node.mult_factor = factor sequence_node.mult_factor = factor
return sequence_node return sequence_node
def visit_FormattedValueNode(self, node):
self.visitchildren(node)
if isinstance(node.format_spec, ExprNodes.UnicodeNode) and not node.format_spec.value:
node.format_spec = None
return node
def visit_JoinedStrNode(self, node): def visit_JoinedStrNode(self, node):
""" """
Clean up after the parser by discarding empty Unicode strings and merging Clean up after the parser by discarding empty Unicode strings and merging
...@@ -3960,7 +3966,6 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): ...@@ -3960,7 +3966,6 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
""" """
self.visitchildren(node) self.visitchildren(node)
unicode_node = ExprNodes.UnicodeNode unicode_node = ExprNodes.UnicodeNode
format_node = ExprNodes.FormattedValueNode
values = [] values = []
for is_unode_group, substrings in itertools.groupby(node.values, lambda v: isinstance(v, unicode_node)): for is_unode_group, substrings in itertools.groupby(node.values, lambda v: isinstance(v, unicode_node)):
...@@ -3973,11 +3978,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations): ...@@ -3973,11 +3978,7 @@ class ConstantFolding(Visitor.VisitorTransform, SkipDeclarations):
if unode.value: if unode.value:
values.append(unode) values.append(unode)
else: else:
for value in substrings: values.extend(substrings)
if isinstance(value, format_node):
if isinstance(value.format_spec, unicode_node) and not value.format_spec.value:
value.format_spec = None
values.append(value)
if not values: if not values:
node = ExprNodes.UnicodeNode(node.pos, value=EncodedString('')) node = ExprNodes.UnicodeNode(node.pos, value=EncodedString(''))
......
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