-
Notifications
You must be signed in to change notification settings - Fork 2k
Add nested-string-quote-style formatting option
#24312
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
Merged
MichaReiser
merged 2 commits into
astral-sh:main
from
matthewlloyd:0.15.8-nested-string-quote-style-pr
Mar 31, 2026
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
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
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
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
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
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
22 changes: 22 additions & 0 deletions
22
..._formatter/resources/test/fixtures/ruff/expression/nested_string_quote_style.options.json
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| [ | ||
| { | ||
| "quote_style": "double", | ||
| "target_version": "3.14", | ||
| "nested_string_quote_style": "alternating" | ||
| }, | ||
| { | ||
| "quote_style": "double", | ||
| "target_version": "3.14", | ||
| "nested_string_quote_style": "preferred" | ||
| }, | ||
| { | ||
| "quote_style": "double", | ||
| "target_version": "3.11", | ||
| "nested_string_quote_style": "alternating" | ||
| }, | ||
| { | ||
| "quote_style": "double", | ||
| "target_version": "3.11", | ||
| "nested_string_quote_style": "preferred" | ||
| } | ||
| ] |
81 changes: 81 additions & 0 deletions
81
...uff_python_formatter/resources/test/fixtures/ruff/expression/nested_string_quote_style.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,81 @@ | ||
| # Nested string literals inside interpolated string expressions follow either | ||
| # alternating or preferred quote normalization depending on | ||
| # nested-string-quote-style. | ||
|
|
||
| # Nested string literals. | ||
| f'{ "nested" }' | ||
| t'{ "nested" }' | ||
|
|
||
| # Multiple levels of nested interpolated strings. | ||
| f'level 1 {f"level 2"}' | ||
| t'level 1 {f"level 2"}' | ||
| f'''level 1 {f"level 2 {f'level 3'}"}''' | ||
| t'''level 1 {f"level 2 {f'level 3'}"}''' | ||
| f'level 1 {f"level 2 {f'level 3'}"}' # syntax error pre-3.12 | ||
| f'level 1 {f"level 2 {f'level 3 {f"level 4"}'}"}' # syntax error pre-3.12 | ||
|
|
||
| # Nested string literals with equal specifiers (debug expressions). | ||
| f'{ "nested" = }' | ||
| t'{ "nested" = }' | ||
| f"{10 + len('bar')=}" | ||
| t"{10 + len('bar')=}" | ||
|
|
||
| # Escape minimization. | ||
| f'"double" quotes and {"nested string"}' | ||
| t'"double" quotes and {"nested string"}' | ||
| f"'single' quotes and {'nested string'}" | ||
| t"'single' quotes and {'nested string'}" | ||
| f'"double" quotes and {"nested string with \"double\" quotes"}' # syntax error pre-3.12 | ||
| t'"double" quotes and {"nested string with \"double\" quotes"}' | ||
| f"'single' quotes and {'nested string with \'single\' quotes'}'" # syntax error pre-3.12 | ||
| t"'single' quotes and {'nested string with \'single\' quotes'}'" | ||
| f'"double" quotes and {"nested string with 'single' quotes"}' # syntax error pre-3.12 | ||
| t'"double" quotes and {"nested string with 'single' quotes"}' | ||
| f"'single' quotes and {'nested string with "double" quotes'}'" # syntax error pre-3.12 | ||
| t"'single' quotes and {'nested string with "double" quotes'}'" | ||
|
|
||
| # Nested strings in lists and dictionaries. | ||
| f'{ ["1", "2"] }' | ||
| t'{ ["1", "2"] }' | ||
| f'{ {"key": [{"inner": "value"}]} }' | ||
| t'{ {"key": [{"inner": "value"}]} }' | ||
|
|
||
| # Triple quotes and escaped quotes. | ||
| f'''{ "'single'" }''' | ||
| t'''{ "'single'" }''' | ||
| f'''{ '"double"' }''' | ||
| t'''{ '"double"' }''' | ||
| f''''single' { "'single'" }''' | ||
| t''''single' { "'single'" }''' | ||
| f'''"double" { '"double"' }''' | ||
| t'''"double" { '"double"' }''' | ||
| f''''single' { '"double"' }''' | ||
| t''''single' { '"double"' }''' | ||
| f'''"double" { "'single'" }''' | ||
| t'''"double" { "'single'" }''' | ||
|
|
||
| # Triple quotes and nested f-strings. | ||
| f"{f'''{'nested'} inner'''} outer" | ||
| t"{t'''{'nested'} inner'''} outer" | ||
|
|
||
| # Outer implicit concatenation. | ||
| f'{ "implicit " }' f'{ "concatenation" }' | ||
| t'{ "implicit " }' t'{ "concatenation" }' | ||
|
|
||
| # Outer implicit concatenation with escaped quotes. | ||
| f'"double" quotes and { "implicit " }' f'{ "concatenation" } with "double" quotes' | ||
| t'"double" quotes and { "implicit " }' t'{ "concatenation" } with "double" quotes' | ||
| f'\'single\' quotes and { "implicit " }' f'{ "concatenation" } with "double" quotes' | ||
| t'\'single\' quotes and { "implicit " }' t'{ "concatenation" } with "double" quotes' | ||
| f'"double" quotes and { "implicit " }' f'{ "concatenation" } with \'single\' quotes' | ||
| t'"double" quotes and { "implicit " }' t'{ "concatenation" } with \'single\' quotes' | ||
| f'\'single\' quotes and { "implicit " }' f'{ "concatenation" } with \'single\' quotes' | ||
| t'\'single\' quotes and { "implicit " }' t'{ "concatenation" } with \'single\' quotes' | ||
|
|
||
| # Inner implicit concatenation. | ||
| f'{ ("implicit " "concatenation", ["more", "strings"]) }' | ||
| t'{ ("implicit " "concatenation", ["more", "strings"]) }' | ||
|
|
||
| # Inner implicit concatenation with escaped quotes. | ||
| f'{ ("implicit " "concatenation", ["'single'", "\"double\""]) }' | ||
| t'{ ("implicit " "concatenation", ["'single'", "\"double\""]) }' |
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
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
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
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.