Skip to content

Commit 2c135ed

Browse files
Handle # fmt: skip followed by a comment (#4635)
1 parent 6144c46 commit 2c135ed

File tree

3 files changed

+8
-1
lines changed

3 files changed

+8
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
- Fix crash while formatting a long `del` statement containing tuples (#4628)
1313
- Fix crash while formatting expressions using the walrus operator in complex
1414
`with` statements (#4630)
15+
- Handle `# fmt: skip` followed by a comment at the end of file (#4635)
1516

1617
### Preview style
1718

src/black/comments.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def _generate_ignored_nodes_from_fmt_skip(
321321
if not comments or comment.value != comments[0].value:
322322
return
323323
if prev_sibling is not None:
324-
leaf.prefix = ""
324+
leaf.prefix = leaf.prefix[comment.consumed :]
325325

326326
if Preview.fix_fmt_skip_in_one_liners not in mode:
327327
siblings = [prev_sibling]

tests/data/cases/fmtskip11.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
def foo():
2+
pass
3+
4+
5+
# comment 1 # fmt: skip
6+
# comment 2

0 commit comments

Comments
 (0)