File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 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 -->
Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 33# Regression test for https://github.com/psf/black/issues/3438
44
55import ast
6+
67import collections # fmt: skip
78import dataclasses
9+
810# fmt: off
911import os
1012# fmt: on
You can’t perform that action at this time.
0 commit comments