-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add f-string consistent quotes formatting option #16385
base: main
Are you sure you want to change the base?
Conversation
Introduces a new formatter option `f-string-consistent-quotes` that leverages Python 3.12's PEP 701 to use consistent quotes inside f-string expressions rather than alternating quote styles for compatibility. When enabled and targeting Python 3.12+, the formatter will use the same quote style (following the `quote-style` setting) inside f-string expressions as in the outer f-string. This produces more consistent and readable code. When disabled (default) or targeting Python versions below 3.12, the formatter will continue to alternate quotes for compatibility. 🤖 Generated with Claude Code Co-Authored-By: Claude <[email protected]>
|
Thanks for working on this. I don't feel like I've enough information/conviction yet that we should introduce this option. That's why I prefer to wait with this change a little longer. |
Thanks for considering this PR. I'd like to clarify a few points that might help with the decision:
What additional information would be helpful to move this forward? I'm happy to address any specific concerns about the implementation or rationale. |
It's mainly that I'm not sure that there's enough demand to justify an extra option. We don't have as high a bar as black on options but we still maintain a fairly high bar on new options because each option introduces the risk that people now start discussing options instead of formatting decisions. That's why I want to wait a little longer to see if there's more demand for the option introduced in this PR |
Thanks for the feedback. I understand your concern about demand, but I'd like to respectfully point out that you accepted and implemented the original feature request to make quote styles alternating (#11056) even though it had been requested by and had support from only a single user. This feature has been requested by six users already. The original change to enforce alternating quotes made in 2024 was made to cater to a narrow use case - backporting to Python versions released before 2022 - while this configuration option will benefit all current users of Python 3.12 (released two years ago already, in 2023) and all future versions. Given that Python's trajectory is clearly moving toward consistent quote handling in f-strings with PEP 701, it seems reasonable to provide users the option to follow this modern approach. Additionally, this is a non-default configuration option that requires explicit opt-in, so it doesn't impact existing users or add complexity to the default experience. It simply provides flexibility for those who want to leverage Python 3.12's improved f-string capabilities. |
I would very much like to see this merged. I am currently postponing upgrading ruff to ^0.9 in my repo, because I do not like the alternating style. I was surprised that the option for consistent quotes was not already present when I saw the default was to alternate quotes. It seems weird to not be able to opt in to something, that in my opinion should be the default behavior after python 3.11 end of life. I do not believe we should be restricted by limitations of old versions forever, and allowing the transition to happen sooner on an opt in basis will only make it smoother. |
Introduces a new formatter option
f-string-consistent-quotes
that leverages Python 3.12's PEP 701 to use consistent quotes inside f-string expressions rather than alternating quote styles for compatibility.When enabled and targeting Python 3.12+, the formatter will use the same quote style (following the
quote-style
setting) inside f-string expressions as in the outer f-string. This produces more consistent and readable code.When disabled (default) or targeting Python versions below 3.12, the formatter will continue to alternate quotes for compatibility.
Implements: #14118