diff --git a/CHANGES.md b/CHANGES.md index 36cbd0039e0..ad1bd0118e3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -14,6 +14,7 @@ - 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 3bce0ef07b7..90487fb0f18 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 00000000000..9aee769c8f3 --- /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