Commit 0a631b46 authored by Stefan Behnel's avatar Stefan Behnel

discard empty substrings from the join-list of f-strings

parent 2fa17728
...@@ -349,10 +349,23 @@ class PostParse(ScopeTrackingTransform): ...@@ -349,10 +349,23 @@ class PostParse(ScopeTrackingTransform):
return node return node
def visit_JoinedStrNode(self, node): def visit_JoinedStrNode(self, node):
if len(node.values) == 1: """
# this is not uncommon because f-string format specs are parsed into JoinedStrNodes Clean up after the parser by wrapping the substrings in a ListNode and
return node.values[0] discarding empty Unicode strings. Empty or single-value join lists are not
node.values = ExprNodes.ListNode(node.pos, args=node.values) uncommon because f-string format specs are always parsed into JoinedStrNodes.
"""
values = []
for value in node.values:
if isinstance(value, ExprNodes.UnicodeNode) and not value.value:
continue # ignore empty Unicode strings
values.append(value)
if not values:
node = ExprNodes.UnicodeNode(node.pos, value=EncodedString(''))
elif len(values) == 1:
node = values[0]
else:
node.values = ExprNodes.ListNode(node.pos, args=values)
self.visitchildren(node) self.visitchildren(node)
return node return node
......
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