-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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 --single-quote option #594
Comments
I agree that having this option would make sense as the current situation is ignoring the community wishes. Currently it requires everyone who uses single quotes to run black and then have a second tool (we use pre-commit I even think that removing Add this option is the outcome that would mostly satisfy #373 and #118 |
What exactly is the need? |
To add an option to default to single quote instead of double quote. Prettier's behaviour would be the best actually:
|
@hyperknot black does exactly what you suggest in your last example. Black also chooses the one which results in the fewest number of escapes, and in the case of a tie it prefers double quotes. |
|
@zsol that's great to hear! I didn't know black has so high quality internal quote handling. Then adding this option is really just a matter of decision, and I kindly ask you to please consider our feature request. |
The claim that single quotes are more Pythonic is dubious. PEP8 makes it clear neither is preferred:
This is an opinionated formatter, it's important to choose one style and stick with it. I want to see black-formatted code and feel familiar with it. The fewer code-style options for my team to argue about, the better. |
@bcb this is the difference between an individual and a community. You, as an individual are happy with the tool and that's fine. No one is proposing to take anything away from you or your team. Everything would work for you as it does today. The community, on the other hand is not going to change their coding style based on the preference of a tool. Python is a mature language with lot of experienced, senior developers who have a strong opinion about the way they use quotation marks. If single quotation marks are not an option in black, they'll simply use The same happened in JS land. StandardJS was trying to force the JS ecosystem to semicolon less statement endings, and many couldn't accept that. Came prettier, which offered both options for semicolon and it became a community embraced project overnight! |
One of the guiding principles of black is to offer only one style, so it's either going to prefer single or double quotes but not both. I would love to hear convincing arguments in favor of single quotes, which is why this issue is still open. Please focus the discussion on arguments for why single quotes should be the only thing black defaults to, instead of just a flavor tunable with configuration. |
@zsol single and double quotes are about a 50-50 in the Python community. The whole community will never pick one over the other. Even the PEP guide says that both are ok. Then why would a tool like black think that it can change this? If you want to support only one of them (doesn't matter which one), there'll be two consequences:
Then instead of unifying Python developers, you've actually split the black community between two forks. |
Opinionated except for line-length, skip-string-normalization and skip-numeric-underscore-normalization
@zsol All the arguments have been made already in #118 and #373 but I shall copy some over:
|
@zsol It's too late for that now, months ago perhaps it was possible but the traction that black has gained will cause a furore if you switched to enforcing single-quotes. |
There are accessibility concerns regarding this choice as well that were overlooked in #118:
Having a flag for this would be fantastic! |
I didn't think of the accessibility concerns as well. But it might be one of the reasons why more and more code I read is standardising on single quotes, across languages which support both. |
Add support for `black -s|--single-quotes`. Fixes psf#594
I added support for |
Add support for `black -s|--single-quotes`. Fixes psf#594
Add support for `black -s|--single-quotes`. Fixes psf#594
Add support for `black -s|--single-quotes`. Fixes psf#594
We will not be adding single quotes formatting to Black as previous discussions about it documented. |
Prettier, the most successful "opinionated code formatter", probably an inspiration for this project, advertises exactly the same values as this project. In many ways they make even stricter formatting decisions than black.
Yet, even prettier supports a
--single-quote
option.Please add a
--single-quote
option to black.And before immediately closing this ticket, please understand there is a huge need from users to have this option. At least go as far as to search across Github for
pyproject.toml
file's[tool.black]
and check how many major projects have to use black withskip-string-normalization = true
. Or simply listen to your users here.The text was updated successfully, but these errors were encountered: