-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Normalize implicit concatenated f-string quotes per part #13539
Normalize implicit concatenated f-string quotes per part #13539
Conversation
|
Uff, I might have to gate this behind preview :( I'm not sure why this isn't local to f-string formatting only. Black uses the same layout as this PR proposes. |
I believe this is related to #13237 because the formatter always preserves the quotes if the expression contains a quote anywhere (even inside a string). This seems odd to me @dhruvmanila could you help me understand why this is in place? |
This might actually be a bug in ruff. For example, it fails to normalise the quotes for "aaaa" f'bbbbb{'c'}b' Where black handles this successfully. |
I'm looking into this... |
Yeah, this seems like a bug and I think it's the same as #13237 |
Based on the previous comment (#9058 (comment)), I think it was so that the quoting effect remains same throughout the f-string but I'm realizing now that it doesn't matter. For example, I'm guessing that my thought process was to keep this formatted as single quote for both string and f-string ( |
a519890
to
2d542bd
Compare
ca44e51
to
0f47c8a
Compare
StringLiteralKind::InImplicitConcatenatedFString
kind@@ -19,6 +19,13 @@ pub(crate) fn is_f_string_formatting_enabled(context: &PyFormatContext) -> bool | |||
context.is_preview() | |||
} | |||
|
|||
/// See [#13539](https://github.com/astral-sh/ruff/pull/13539) | |||
pub(crate) fn is_f_string_implicit_concatenated_string_literal_quotes_enabled( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created a new preview style for now in case we push out the f-string stabilization. We can merge this change with the f-string preview style if we decide to ship both changes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks for fixing this
This PR fixes a bug where ruff decided on whether the quotes for an implicit concatenated string can be changed for the entire expression instead of deciding on the part-level.
Input
Stable
Notice how the formatter doesn't change any quotes only because one f-string has an expression containing double quotes.
Preview
This matches black and how Ruff normalizes quotes for regular string literals (the decision is made per literal and for the entire implicit concatenated string expression)