Add nested-string-quote-style formatting option#24312
Merged
MichaReiser merged 2 commits intoastral-sh:mainfrom Mar 31, 2026
Merged
Add nested-string-quote-style formatting option#24312MichaReiser merged 2 commits intoastral-sh:mainfrom
nested-string-quote-style formatting option#24312MichaReiser merged 2 commits intoastral-sh:mainfrom
Conversation
Introduces a new formatter option `nested-string-quote-style` that leverages Python 3.12's PEP 701 to use preferred quotes inside f-string expressions rather than alternating quote styles for compatibility. When set to `preferred` and targeting Python 3.12+, the formatter uses the user's preferred quote style (following the `quote-style` setting) inside f-string expressions. When set to `alternating` (default) or targeting Python versions below 3.12, the formatter continues to alternate quotes.
|
MichaReiser
approved these changes
Mar 31, 2026
Member
MichaReiser
left a comment
There was a problem hiding this comment.
Thanks. This looks good to me.
I only have a few small comments about adding some more tests and around documentation
...ython_formatter/resources/test/fixtures/ruff/expression/fstring_nested_string_quote_style.py
Outdated
Show resolved
Hide resolved
...ython_formatter/tests/snapshots/format@expression__fstring_nested_string_quote_style.py.snap
Outdated
Show resolved
Hide resolved
* Add many tests * Adjust documentation text
nested-string-quote-style formatting option
Contributor
Author
|
Thanks also for your patience and thorough review! |
carljm
added a commit
that referenced
this pull request
Apr 1, 2026
* main: [ty] Add missing test case for inline functional TypedDict with an invalid type passed to the `name` parameter (#24334) [ty] Use `_cls` as argument name for `collections.namedtuple` (#24333) [ty] Emit diagnostic for functional TypedDict with non-literal name (#24331) Add `nested-string-quote-style` formatting option (#24312) `RUF010`: Mark fix as unsafe when it deletes a comment [ty] Fix semantic token classification for properties accessed on instances (#24065) publish installers to `/installers/ruff/latest` on the mirror (#24247)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Introduces a new formatter option
nested-string-quote-stylethat leverages Python 3.12's PEP 701 to use preferred quotes inside f- and t-string expressions rather than alternating quote styles for compatibility.When set to
preferredand targeting Python 3.12+, the formatter uses the user's preferred quote style (following thequote-stylesetting) inside f-string expressions.When set to
alternating(default) or targeting Python versions below 3.12, the formatter continues to alternate quotes.Implements: #14118
Replaces PR: #23098