From 0181172cc33f70bdaf66d10611bbbe0e01e587e8 Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Tue, 5 Dec 2023 18:05:50 +0100
Subject: [PATCH 1/3] fix crash in preview mode with --line-length=1
---
src/black/linegen.py | 2 +-
.../return_annotation_brackets_crash_line_length_1.py | 9 +++++++++
2 files changed, 10 insertions(+), 1 deletion(-)
create mode 100644 tests/data/cases/return_annotation_brackets_crash_line_length_1.py
diff --git a/src/black/linegen.py b/src/black/linegen.py
index 7152568783e..073672a5ae7 100644
--- a/src/black/linegen.py
+++ b/src/black/linegen.py
@@ -744,7 +744,7 @@ def left_hand_split(
if leaf.type in OPENING_BRACKETS:
matching_bracket = leaf
current_leaves = body_leaves
- if not matching_bracket:
+ if not matching_bracket or not tail_leaves:
raise CannotSplit("No brackets found")
head = bracket_split_build_line(
diff --git a/tests/data/cases/return_annotation_brackets_crash_line_length_1.py b/tests/data/cases/return_annotation_brackets_crash_line_length_1.py
new file mode 100644
index 00000000000..9d96b4ab97a
--- /dev/null
+++ b/tests/data/cases/return_annotation_brackets_crash_line_length_1.py
@@ -0,0 +1,9 @@
+# flags: --preview --minimum-version=3.10 --line-length=1
+
+def foo() -> tuple[int, int,]:
+ ...
+# output
+def foo() -> tuple[
+ int,
+ int,
+]: ...
From 1d5cbc5f5a86d5d4911cda1f441614914ba977be Mon Sep 17 00:00:00 2001
From: jakkdl
Date: Tue, 5 Dec 2023 18:29:00 +0100
Subject: [PATCH 2/3] add changelog
---
CHANGES.md | 1 +
1 file changed, 1 insertion(+)
diff --git a/CHANGES.md b/CHANGES.md
index f17cd7fdc9d..e3dd1f41f17 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -17,6 +17,7 @@
- Standalone form feed characters at the module level are no longer removed (#4021)
- Additional cases of immediately nested tuples, lists, and dictionaries are now
indented less (#4012)
+- fix crash in preview mode when using a short --line-length (#4086)
### Configuration
From 05f29100dc5df6b2d837256ffa3fa59cb749f89e Mon Sep 17 00:00:00 2001
From: Jelle Zijlstra
Date: Tue, 5 Dec 2023 09:36:21 -0800
Subject: [PATCH 3/3] Update CHANGES.md
---
CHANGES.md | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/CHANGES.md b/CHANGES.md
index e3dd1f41f17..8f0b75e7f10 100644
--- a/CHANGES.md
+++ b/CHANGES.md
@@ -17,7 +17,7 @@
- Standalone form feed characters at the module level are no longer removed (#4021)
- Additional cases of immediately nested tuples, lists, and dictionaries are now
indented less (#4012)
-- fix crash in preview mode when using a short --line-length (#4086)
+- Fix crash in preview mode when using a short `--line-length` (#4086)
### Configuration