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 #4350
  • Loading branch information
hauntsaninja committed May 16, 2024
1 parent b9c6323 commit 7f16616
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/black/linegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,18 @@ 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 any(
"\\" 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 7f16616

Please sign in to comment.