Skip to content

Commit 2080318

Browse files
committed
Gating change to preview style, fixed merge conflict
1 parent 800ca38 commit 2080318

3 files changed

Lines changed: 17 additions & 3 deletions

File tree

CHANGES.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@
1818
- Fix crash when multiple `# fmt: skip` comments are used in a multi-part if-clause, on
1919
string literals, or on dictionary entries with long lines (#4872)
2020
- Fix possible crash when `fmt: ` directives aren't on the top level (#4856)
21-
- Fix bug where `if` guards in `case` blocks were incorrectly split when the pattern had
22-
a trailing comma (#4884)
2321

2422
### Preview style
2523

2624
<!-- Changes that affect Black's preview style -->
2725

26+
- Fix bug where `if` guards in `case` blocks were incorrectly split when the pattern had
27+
a trailing comma (#4884)
28+
2829
### Configuration
2930

3031
<!-- Changes to how Black can be configured -->

src/black/linegen.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1594,7 +1594,18 @@ def normalize_invisible_parens(
15941594
break
15951595

15961596
elif not is_multiline_string(child):
1597-
wrap_in_parentheses(node, child, visible=False)
1597+
if mode.preview:
1598+
if node.type == syms.guard:
1599+
mock_line = Line(mode=mode)
1600+
for leaf in child.leaves():
1601+
mock_line.append(leaf)
1602+
# If it's a guard AND it's short, we DON'T wrap
1603+
if not is_line_short_enough(mock_line, mode=mode):
1604+
wrap_in_parentheses(node, child, visible=False)
1605+
else:
1606+
wrap_in_parentheses(node, child, visible=False)
1607+
else:
1608+
wrap_in_parentheses(node, child, visible=False)
15981609

15991610
comma_check = child.type == token.COMMA
16001611

tests/data/cases/preview_fmtpass_imports.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
# Regression test for https://github.com/psf/black/issues/3438
44

55
import ast
6+
67
import collections # fmt: skip
78
import dataclasses
9+
810
# fmt: off
911
import os
1012
# fmt: on

0 commit comments

Comments
 (0)