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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

hauntsaninja
Copy link
Collaborator

Fixes #4350

Copy link

github-actions bot commented May 16, 2024

diff-shades reports zero changes comparing this PR (7f16616) to main (9c1fd46).


What is this? | Workflow run | diff-shades documentation

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

@tusharsadhwani
Copy link
Contributor

tusharsadhwani commented Jul 2, 2024

Personally I'd rewrite it like so:

if (
    "\\" in string_leaf.value
    and any(
        "\\" in str(child)
        for child in node.children
        if child.type == syms.fstring_replacement_field
    )
):
    # string normalization doesn't account for nested quotes,
    # causing breakages. skip normalization when nested quotes exist
    yield from self.visit_default(string_leaf)
    return
yield from self.visit_STRING(string_leaf)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"EOF in multi-line string" on string containing same quote nested in f-string
2 participants