Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix formatting of backslash escaped quote inside f-string #4365

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if node.type == syms.fstring_replacement_field
if child.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
Loading