Fix crash on standalone comment in lambda default arguments (#4993) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: cobalt <61329810+cobaltt7@users.noreply.github.com>
diff --git a/CHANGES.md b/CHANGES.md index 36cbd00..ad1bd01 100644 --- a/CHANGES.md +++ b/CHANGES.md
@@ -14,6 +14,7 @@ <!-- Changes that affect Black's stable style --> - Don't double-decode input, causing non-UTF-8 files to be corrupted (#4964) +- Fix crash on standalone comment in lambda default arguments (#4993) ### Preview style
diff --git a/src/black/nodes.py b/src/black/nodes.py index 3bce0ef..90487fb 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py
@@ -689,7 +689,7 @@ def is_one_sequence_between( break else: - raise LookupError("Opening paren not found in `leaves`") + return False commas = 0 _opening_index += 1
diff --git a/tests/data/cases/comments_in_lambda_default.py b/tests/data/cases/comments_in_lambda_default.py new file mode 100644 index 0000000..9aee769 --- /dev/null +++ b/tests/data/cases/comments_in_lambda_default.py
@@ -0,0 +1,27 @@ +help(lambda x=( + # comment + "bar", +): False) + +result = (lambda x=( + # a standalone comment + 1, + 2, + 3, +): x) + +# output + +help( + lambda x=( + # comment + "bar", + ): False, +) + +result = lambda x=( + # a standalone comment + 1, + 2, + 3, +): x