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

formatter bug: f-strings with triple quotes #6841

Closed
davidszotten opened this issue Aug 24, 2023 · 1 comment · Fixed by #7826
Closed

formatter bug: f-strings with triple quotes #6841

davidszotten opened this issue Aug 24, 2023 · 1 comment · Fixed by #7826
Assignees
Labels
bug Something isn't working formatter Related to the formatter

Comments

@davidszotten
Copy link
Contributor

the formatter is too conservative when making sure it doesn't try to escape quotes inside formatted values, and doesn't take into account triple quotes

input: f''' {""} '''
output: f''' {""} '''
expected: f""" {""} """

i expect

Self::FString(f_string) => {
if f_string.values.iter().any(|value| match value {
Expr::FormattedValue(ast::ExprFormattedValue { range, .. }) => {
let string_content = locator.slice(*range);
string_content.contains(['"', '\''])
}
_ => false,
needs to be more sophisticated

@MichaReiser MichaReiser added bug Something isn't working formatter Related to the formatter labels Aug 24, 2023
@MichaReiser MichaReiser added this to the Formatter: Beta milestone Aug 24, 2023
@konstin konstin self-assigned this Sep 12, 2023
@davidszotten
Copy link
Contributor Author

it's been a while now (blocked on #6365 for a few weeks)
but iirc i made this slightly better in my "proper f-string formatting" poc https://github.com/davidszotten/ruff/pull/1/files#diff-9ae227f70699315433485961eb6bbeb9a45487857fbfebe473e926e71bc194f5R46

konstin added a commit that referenced this issue Oct 5, 2023
**Summary** Quoting of f-strings can change if they are triple quoted and only contain single quotes inside.

Fixes #6841

**Test Plan** New fixtures
konstin added a commit that referenced this issue Oct 11, 2023
**Summary** Quoting of f-strings can change if they are triple quoted and only contain single quotes inside.

Fixes #6841

**Test Plan** New fixtures
konstin added a commit that referenced this issue Oct 11, 2023
**Summary** Quoting of f-strings can change if they are triple quoted
and only contain single quotes inside.

Fixes #6841

**Test Plan** New fixtures

---------

Co-authored-by: Dhruv Manilawala <dhruvmanila@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working formatter Related to the formatter
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants