Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 73c2d55

Browse files
authored
Fix a crash in ESP where a standalone comment is placed before a dict's value (psf#3469)
1 parent a44dc3d commit 73c2d55

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

CHANGES.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
and except clauses (#3423)
2222
- Fix a crash in preview advanced string processing where mixed implicitly concatenated
2323
regular and f-strings start with an empty span (#3463)
24+
- Fix a crash in preview advanced string processing where a standalone comment is placed
25+
before a dict's value (#3469)
2426
- Do not put the closing quotes in a docstring on a separate line, even if the line is
2527
too long (#3430)
2628
- Long values in dict literals are now wrapped in parentheses; correspondingly

src/black/trans.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ def _dict_or_lambda_match(LL: List[Leaf]) -> Optional[int]:
18661866

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

18721872
# That colon MUST be followed by a string...

tests/data/preview/long_strings__regression.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,6 +543,13 @@ async def foo(self):
543543
f'xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}',
544544
)
545545

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

547554
# output
548555

@@ -1221,3 +1228,10 @@ async def foo(self):
12211228
f"xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}"
12221229
),
12231230
)
1231+
1232+
# Regression test for https://github.com/psf/black/issues/3455.
1233+
a_dict = {
1234+
"/this/is/a/very/very/very/very/very/very/very/very/very/very/long/key/without/spaces":
1235+
# And there is a comment before the value
1236+
("item1", "item2", "item3"),
1237+
}

0 commit comments

Comments
 (0)