Skip to content

Add nested-string-quote-style formatting option#24312

Merged
MichaReiser merged 2 commits intoastral-sh:mainfrom
matthewlloyd:0.15.8-nested-string-quote-style-pr
Mar 31, 2026
Merged

Add nested-string-quote-style formatting option#24312
MichaReiser merged 2 commits intoastral-sh:mainfrom
matthewlloyd:0.15.8-nested-string-quote-style-pr

Conversation

@matthewlloyd
Copy link
Copy Markdown
Contributor

@matthewlloyd matthewlloyd commented Mar 30, 2026

Introduces a new formatter option nested-string-quote-style that 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 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.

Implements: #14118
Replaces PR: #23098

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.
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 30, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@MichaReiser MichaReiser added formatter Related to the formatter configuration Related to settings and configuration labels Mar 31, 2026
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thanks. This looks good to me.

I only have a few small comments about adding some more tests and around documentation

* Add many tests
* Adjust documentation text
Copy link
Copy Markdown
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

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

Thank you. This is great

@MichaReiser MichaReiser changed the title Add nested-string-quote-style formatting option Add nested-string-quote-style formatting option Mar 31, 2026
@MichaReiser MichaReiser merged commit 6468a35 into astral-sh:main Mar 31, 2026
42 checks passed
@matthewlloyd
Copy link
Copy Markdown
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

configuration Related to settings and configuration formatter Related to the formatter

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants