Skip to content

Commit

Permalink
Fix formatting of backslash escaped quote inside f-string
Browse files Browse the repository at this point in the history
Fixes psf#4350
  • Loading branch information
hauntsaninja committed May 16, 2024
1 parent b9c6323 commit 01b072d
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,15 @@ def visit_fstring(self, node: Node) -> Iterator[Line]:
# currently we don't want to format and split f-strings at all.
string_leaf = fstring_to_string(node)
node.replace(string_leaf)
yield from self.visit_STRING(string_leaf)
if "\\" not in string_leaf.value and all(
"\\" not in str(child)
for child in node.children
if node.type == syms.fstring_replacement_field
):
yield from self.visit_STRING(string_leaf)
return
yield from self.visit_default(string_leaf)
return

# TODO: Uncomment Implementation to format f-string children
# fstring_start = node.children[0]
Expand Down

0 comments on commit 01b072d

Please sign in to comment.