Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix a crash in ESP where a standalone comment is placed before a dict's value. #3469

Merged
merged 1 commit into from Dec 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -21,6 +21,8 @@
and except clauses (#3423)
- Fix a crash in preview advanced string processing where mixed implicitly concatenated
regular and f-strings start with an empty span (#3463)
- Fix a crash in preview advanced string processing where a standalone comment is placed
before a dict's value (#3469)
- Do not put the closing quotes in a docstring on a separate line, even if the line is
too long (#3430)
- Long values in dict literals are now wrapped in parentheses; correspondingly
Expand Down
2 changes: 1 addition & 1 deletion src/black/trans.py
Expand Up @@ -1866,7 +1866,7 @@ def _dict_or_lambda_match(LL: List[Leaf]) -> Optional[int]:

for i, leaf in enumerate(LL):
# We MUST find a colon, it can either be dict's or lambda's colon...
if leaf.type == token.COLON:
if leaf.type == token.COLON and i < len(LL) - 1:
idx = i + 2 if is_empty_par(LL[i + 1]) else i + 1

# That colon MUST be followed by a string...
Expand Down
14 changes: 14 additions & 0 deletions tests/data/preview/long_strings__regression.py
Expand Up @@ -543,6 +543,13 @@ async def foo(self):
f'xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}',
)

# Regression test for https://github.com/psf/black/issues/3455.
a_dict = {
"/this/is/a/very/very/very/very/very/very/very/very/very/very/long/key/without/spaces":
# And there is a comment before the value
("item1", "item2", "item3"),
}


# output

Expand Down Expand Up @@ -1221,3 +1228,10 @@ async def foo(self):
f"xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}"
),
)

# Regression test for https://github.com/psf/black/issues/3455.
a_dict = {
"/this/is/a/very/very/very/very/very/very/very/very/very/very/long/key/without/spaces":
# And there is a comment before the value
("item1", "item2", "item3"),
}