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: don't try to format strings inside f-strings #4401

Merged
merged 3 commits into from
Jul 11, 2024

Conversation

tusharsadhwani
Copy link
Contributor

@tusharsadhwani tusharsadhwani commented Jul 10, 2024

Resolves #4350 , closes #4365

If a string like '\'' is inside a double-quoted f-string, like f"{'\''}" the formatter would break trying to remove the escaped \' quote.

This is because normalize_string_quotes looks at the entire f"{'\''}" input, and the outermost quotes ", hence determining that the \' escape is unnecessary.

To avoid these cases, we don't try to normalize inner strings inside f-string braces.

@tusharsadhwani tusharsadhwani changed the title fix: don't try to format internal f-strings fix: don't try to format strings inside f-strings Jul 10, 2024
Copy link

diff-shades reports zero changes comparing this PR (b52892e) to main (7e2afc9).


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

Copy link
Collaborator

@hauntsaninja hauntsaninja left a comment

Choose a reason for hiding this comment

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

Thanks, looks like an actually correct version of #4365 :-)

This has an amusing interaction with the stability policy, but better to have not the final formatting we want than have a crash

@hauntsaninja hauntsaninja merged commit 721dff5 into psf:main Jul 11, 2024
46 checks passed
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