Skip to content

Commit

Permalink
clean up unnecessary parts
Browse files Browse the repository at this point in the history
  • Loading branch information
sunmy2019 committed Sep 5, 2023
1 parent 9b1b5dd commit 88394d1
Showing 1 changed file with 2 additions and 12 deletions.
14 changes: 2 additions & 12 deletions Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1225,17 +1225,7 @@ def _write_str_avoiding_backslashes(self, string, *, quote_types=_ALL_QUOTES):

def visit_JoinedStr(self, node):
self.write("f")
if self._avoid_backslashes:
with self.buffered() as buffer:
self._write_fstring_inner(node)
return self._write_str_avoiding_backslashes("".join(buffer))

# If we don't need to avoid backslashes globally (i.e., we only need
# to avoid them inside FormattedValues), it's cosmetically preferred
# to use escaped whitespace. That is, it's preferred to use backslashes
# for cases like: f"{x}\n". To accomplish this, we keep track of what
# in our buffer corresponds to FormattedValues and what corresponds to
# Constant parts of the f-string, and allow escapes accordingly.

fstring_parts = []
for value in node.values:
with self.buffered() as buffer:
Expand Down Expand Up @@ -1276,7 +1266,7 @@ def _write_fstring_inner(self, node):

def visit_FormattedValue(self, node):
def unparse_inner(inner):
unparser = type(self)(_avoid_backslashes=False)
unparser = type(self)()
unparser.set_precedence(_Precedence.TEST.next(), inner)
return unparser.visit(inner)

Expand Down

0 comments on commit 88394d1

Please sign in to comment.