10000 Mention comment non-processing in documentation (#2306) · IBMZ-Linux-OSS-Python/black@a9eab85 · GitHub
[go: up one dir, main page]

Skip to content

Commit a9eab85

Browse files
authored
Mention comment non-processing in documentation (psf#2306)
This commit adds a short section discussing the non-processing of docstrings besides spacing improvements, mentions comment moving and links to the AST equivalence discussion. I also added a simple spacing test for good measure. Commit history before merge: * Mention comment non-processing in documentation, add spacing test * Mention special cases for comment spacing * Add all special cases, improve wording
1 parent 40fae18 commit a9eab85

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

docs/the_black_code_style/current_style.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ following field or method. This conforms to
200200
_Black_ won't insert empty lines after function docstrings unless that empty line is
201201
required due to an inner function starting immediately after.
202202

203+
### Comments
204+
205+
_Black_ does not format comment contents, but it enforces two spaces between code and a
206+
comment on the same line, and a space before the comment text begins. Some types of
207+
comments that require specific spacing rules are respected: doc comments (`#: comment`),
208+
section comments with long runs of hashes, and Spyder cells. Non-breaking spaces after
209+
hashes are also preserved. Comments may sometimes be moved because of formatting
210+
changes, which can break tools that assign special meaning to them. See
211+
[AST before and after formatting](#ast-before-and-after-formatting) for more discussion.
212+
203213
### Trailing commas
204214

205215
_Black_ will add trailing commas to expressions that are split by comma where each

tests/data/comments2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ def _init_host(self, parsed) -> None:
159159
#######################
160160

161161

162-
instruction()
162+
instruction()#comment with bad spacing
163163

164164
# END COMMENTS
165165
# MORE END COMMENTS
@@ -336,7 +336,7 @@ def _init_host(self, parsed) -> None:
336336
#######################
337337

338338

339-
instruction()
339+
instruction() # comment with bad spacing
340340

341341
# END COMMENTS
342342
# MORE END COMMENTS

0 commit comments

Comments
 (0)
0