Skip to content

Commit f0f4094

Browse files
authored
Fix new lines being added after imports with # fmt: skip on them (psf#4894)
1 parent 70fc194 commit f0f4094

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

CHANGES.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,14 @@
2121
magic trailing commas and intentional multiline formatting (#4865)
2222
- Fix `fix_fmt_skip_in_one_liners` crashing on `with` statements (#4853)
2323
- Fix `fix_fmt_skip_in_one_liners` crashing on annotated parameters (#4854)
24+
- Fix new lines being added after imports with `# fmt: skip` on them (#4894)
2425

2526
### Packaging
2627

27-
<!-- Changes to how Black is packaged, such as dependency requirements -->
28-
2928
- Releases now include arm64 Windows binaries and wheels (#4814)
3029

3130
### Integrations
3231

33-
<!-- For example, Docker, GitHub Actions, pre-commit, editors -->
34-
3532
- Add `output-file` input to GitHub Action `psf/black` to write formatter output to a
3633
file for artifact capture and log cleanliness (#4824)
3734

src/black/lines.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,7 @@ def _maybe_empty_lines(self, current_line: Line) -> tuple[int, int]:
695695
and self.previous_line.depth == 0
696696
and current_line.depth == 0
697697
and not current_line.is_import
698+
and not current_line.is_fmt_pass_converted(first_leaf_matches=is_import)
698699
and Preview.always_one_newline_after_import in self.mode
699700
):
700701
return 1, 0
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# flags: --preview
2+
3+
# Regression test for https://github.com/psf/black/issues/3438
4+
5+
import ast
6+
import collections # fmt: skip
7+
import dataclasses
8+
# fmt: off
9+
import os
10+
# fmt: on
11+
import pathlib
12+
13+
import re # fmt: skip
14+
import secrets
15+
16+
# fmt: off
17+
import sys
18+
# fmt: on
19+
20+
import tempfile
21+
import zoneinfo

0 commit comments

Comments
 (0)