Skip to content
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 option for single quoted strings as default #4144

Closed
nathanneuro opened this issue Jan 5, 2024 · 2 comments
Closed

Add option for single quoted strings as default #4144

nathanneuro opened this issue Jan 5, 2024 · 2 comments
Labels
T: enhancement New feature or request

Comments

@nathanneuro
Copy link

Is your feature request related to a problem? Please describe.

I'd quite like to have an option to have single-quoted strings be the default.

Problem as described by the Blue formatter ( https://blue.readthedocs.io/en/latest/ ):
"blue defaults to single-quoted strings. This is probably the most painful black choice to our eyes, and the thing that inspired blue. We strongly prefer using single quoted strings over double quoted strings for everything except docstrings and triple quoted strings (TQS). Don’t ask us why we prefer double-quotes for TQS; it just looks better to us! For all other strings, blue defaults to single quoted strings. In the case of docstrings, those always use TQS with double-quotes.
...
We’d prefer not to fork or monkeypatch. Instead, our hope is that eventually we’ll be able to work with the black maintainers to add just a little bit of configuration and merge back into the black project.
"

Describe the solution you'd like

Be able to specify an option to use single-quotes as the default instead of double-quotes (except for triple quoted strings). Much like the 'line length' option, something that people can optionally specify.

Describe alternatives you've considered

  1. using blue formatter instead of black.
  2. gritting my teeth and bearing it.
@nathanneuro nathanneuro added the T: enhancement New feature or request label Jan 5, 2024
@JelleZijlstra
Copy link
Collaborator

I would suggest alternative 2.

Black's philosophy is to minimize formatting options so that formatted code looks consistent and users don't have to worry about formatting minutiae. When I first watched @ambv present about Black, I was also surprised he chose double quotes, but the choice has served us well.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Jan 5, 2024
@sodul
Copy link

sodul commented Jan 9, 2024

@nathanneuro

My workaround has been to add black to gray (v0.10) then have gray call unify after black so that we can get the goodness of black without having to grit our teeth.

Now the issue is that black is incompatible with PEP 701 as reported in #3746, so we end up with files that are formatted in valid python 3.12 syntax but that Black is unable to parse again.

https://github.com/dizballanze/gray

So if you are not on python 3.12 yet and do not like your 2 options, I suggest you take a look at it. Some of the nice things about gray is that it calls other formatting tools such as pyupgrade and isort. Thanks to this our internal codebase has improved well in readability.

BTW I did take a look at option 1, and switching from " to ' would be rather complicated, so it is not just a matter of preference but it would require tricky changes in the codebase.

Now that I'm aware of Blue ... I might add support for it in Gray so that should fix the PEP 701 issue we have and stop using unify.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants