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

Exceptions to comment spacing #3668

Open
JelleZijlstra opened this issue Apr 29, 2023 · 0 comments
Open

Exceptions to comment spacing #3668

JelleZijlstra opened this issue Apr 29, 2023 · 0 comments
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. S: needs discussion Needs further hashing out before ready for implementation (on desirability, feasibility, etc.) T: enhancement New feature or request

Comments

@JelleZijlstra
Copy link
Collaborator

Black enforces that every comment starts with a space, except if the comment starts with a hardcoded list of black.comments.COMMENT_EXCEPTIONS (COMMENT_EXCEPTIONS = " !:#'"). These were added over time to support particular tools that treat certain comments specially. We occasionally get requests to treat more comments specially (#3557) or confusion because of the inclusion of particular characters (#3036). I am opening this issue to focus the discussion and arrive at an overall solution.

Options I'm considering:

  1. Add additional exceptions as people ask for them. I don't want to do this; there is a potentially endless list of tools that treat certain comments specially, and the inconsistent behavior where certain characters suppress the leading space will continue to confuse users who don't have a reason to care about leading spaces in their comments.
  2. Remove all the exceptions. Tell the third-party tools that rely on comments without leading spaces to change their behavior. This simplifies our life, but it's not very collegial.
  3. Don't insert spaces before all non-alphanumeric characters (as suggested in Inconsistent adding of space after # in inline comments depending on single / double quotes used #3036 (comment)). This would make it so we don't have to worry about support for individual tools, but I'd worry that this makes Black's style less consistent: probably many comments in real-world code that start with punctuation without a leading space aren't intended for tools.
  4. Bite the bullet and add a configuration option that allows users to control the COMMENT_EXCEPTIONS. We're generally hesitant to do this because it makes the Black code style less consistent, but I think in this case there's a reasonably strong argument: different projects use different tools, so it makes sense to have a different configuration for this option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. S: needs discussion Needs further hashing out before ready for implementation (on desirability, feasibility, etc.) T: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants