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

Revisit not using Pythonic single quotes #373

Closed
cas-- opened this issue Jun 22, 2018 · 9 comments
Closed

Revisit not using Pythonic single quotes #373

cas-- opened this issue Jun 22, 2018 · 9 comments

Comments

@cas--
Copy link
Contributor

cas-- commented Jun 22, 2018

I was considering letting black format the project code but enforcing double-quotes is a major red flag and honestly shocked by this decision.

Single quotes are Pythonic and have become the defacto standard in recent years, many code checkers (e.g. [flake-quotes]) and standards (e.g. Plone) default/request single quotes. Just because other programming languages use double is not a reason to try to strongarm a different practice onto Python codebases.

Typing single quotes are faster due to not needing to use shift.

It will convert huge swaths of project code for no benefit and negatively effect code history. I know this because I converted from double to single for a large project and was much harder to review code history. Was any consideration made for the number of Python projects using double or single quotes?

You say this project is still in beta so you still have time to change this. Just look at the responses in #118, the community is not happy with this decision, giving quite valid reasons. Skipping checking the quotes is not a good solution as it will result in mixed quotes which is much worse.

I am certainly not asking for the arbitrary mix of double and single depending on intention. Double is only reserved for docstrings or where a single quote is needed in a string.

Please just enforce single quotes as the Python community has mutually agreed upon.

@ambv
Copy link
Collaborator

ambv commented Jun 22, 2018

There is --skip-string-normalization if you feel strongly about this. Most people don't. We won't be changing the default behavior.

@ambv ambv closed this as completed Jun 22, 2018
@jaraco
Copy link
Contributor

jaraco commented Nov 5, 2018

Another point in favor of preferring single quotes to double quotes is that's what Python itself prefers:

>>> print(repr("my string"))
'my string'

In my opinion, that's the strongest argument for why black should prefer single quotes.

This disparity has actually caused an issue in one project. I don't currently have a reference, but if I run across it again, I'll link back here.

@guitarmanvt
Copy link

The main advantage of using a code formatter is that it forces the same formatting. The main advantage of using black in particular is that I can blame you guys for the arbitrary choices you make, and it's no longer "my fault."

Personally, the decision to use double-quotes seems really "pig-headed" to me (for ignoring Python historical convention), but as anyone can see, the black team has provided the option to --skip-string-normalization (for those who are "pig-headed" in the other direction). (Experienced developers will recognize my alternate spelling of "opinionated" in this paragraph. ;) )

Pragmatically, the benefit of having consistent, enforced code formatting outweighs any trivial tastes I or my team have developed over the years. Will I use black? Absolutely. Will I accept all its arbitrary choices? Probably some day.

Until then, it's "good enough." Well done, black team. Don't let people give you grief. (Even about double-quotes.)

@ssbarnea
Copy link
Contributor

The skip option is clearly useful to make adoption easier by delaying normalization for later.

I was wondering myself why double vs single and I found some explanation that makes sense:

  • in English language is more likely to need to use single quote inside a string than double, see "That's good example?"
  • YAML and JSON also standardized on double ones.
  • Most common quoting in literacy is double quotes, not single ones, right?

So there are some reasons.

When it comes to repr(), how about changing it to default to double quotes? Would this break the world?

@psavery
Copy link

psavery commented Oct 7, 2019

Unfortunately, Black's insistence to not add a single quote option is a deal breaker for me as well. I work on several projects that settled on using single-quotes a long time ago, and we strive for consistency. Changing our projects from single quotes to double quotes will not happen easily. And, because we want to enforce single quotes, --skip-string-normalization will not work for us.

Thus, I literally cannot use Black for the time being.

@hugovk
Copy link
Contributor

hugovk commented Oct 7, 2019

@psavery You can use pre-commit to run double-quote-string-fixer (examples):

This hook replaces double quoted strings with single quoted strings

You can use it to chain the Black and double-quote-string-fixer runs into a single command, and even if you don't like Git pre-commit hooks, you can use it as a CLI lint tool: pre-commit run all-files.

@richardARPANET
Copy link

It seems single quotes are most widely used and agreed on in the Python community. Judging by many years of experience along with the various issues listed on this repo.

Whatever the reason for it is irrelevant, more people prefer single.

It's a shame since @ambv wrote this little library then he gets to just wade in and close every issue about it saying in a round-about way "I personally prefer double quotes so no thanks". How a project with such a dictatorial regime gets listed under "https://github.com/psf/" is beyond me.

Maybe this will improve in the future 🤞

@piotr-dobrogost
Copy link

Typing single quotes are faster due to not needing to use shift.

This.

@ambv
Copy link
Collaborator

ambv commented Jan 30, 2020

This is a bad argument. You are using an auto-formatter. Type whatever is faster on your keyboard and let the tool auto-format it for you.

There are no additional points for pre-formatting code manually to look exactly as Black would format it.

There are no additional points for hanging onto closed issues, either. I'm locking this.

@psf psf locked as resolved and limited conversation to collaborators Jan 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants