Skip to content

Commit 50d5756

Browse files
authored
fix crash in preview mode with --line-length=1 (#4086)
1 parent 3416b2c commit 50d5756

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

CHANGES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- Standalone form feed characters at the module level are no longer removed (#4021)
1818
- Additional cases of immediately nested tuples, lists, and dictionaries are now
1919
indented less (#4012)
20+
- Fix crash in preview mode when using a short `--line-length` (#4086)
2021

2122
### Configuration
2223

src/black/linegen.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ def left_hand_split(
744744
if leaf.type in OPENING_BRACKETS:
745745
matching_bracket = leaf
746746
current_leaves = body_leaves
747-
if not matching_bracket:
747+
if not matching_bracket or not tail_leaves:
748748
raise CannotSplit("No brackets found")
749749

750750
head = bracket_split_build_line(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# flags: --preview --minimum-version=3.10 --line-length=1
2+
3+
def foo() -> tuple[int, int,]:
4+
...
5+
# output
6+
def foo() -> tuple[
7+
int,
8+
int,
9+
]: ...

0 commit comments

Comments
 (0)