Skip to content

Commit

Permalink
Fix a crash in ESP where a standalone comment is placed before a dict…
Browse files Browse the repository at this point in the history
…'s value (#3469)
  • Loading branch information
yilei committed Dec 20, 2022
1 parent a44dc3d commit 73c2d55
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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"),
}

0 comments on commit 73c2d55

Please sign in to comment.