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

This commit is contained in:
Yilei "Dolee" Yang 2022-12-20 14:59:38 -08:00 committed by GitHub
parent a44dc3d59e
commit 73c2d5514c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 17 additions and 1 deletions

View File

@ -21,6 +21,8 @@
and except clauses (#3423) and except clauses (#3423)
- Fix a crash in preview advanced string processing where mixed implicitly concatenated - Fix a crash in preview advanced string processing where mixed implicitly concatenated
regular and f-strings start with an empty span (#3463) 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 - Do not put the closing quotes in a docstring on a separate line, even if the line is
too long (#3430) too long (#3430)
- Long values in dict literals are now wrapped in parentheses; correspondingly - Long values in dict literals are now wrapped in parentheses; correspondingly

View File

@ -1866,7 +1866,7 @@ def _dict_or_lambda_match(LL: List[Leaf]) -> Optional[int]:
for i, leaf in enumerate(LL): for i, leaf in enumerate(LL):
# We MUST find a colon, it can either be dict's or lambda's colon... # 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 idx = i + 2 if is_empty_par(LL[i + 1]) else i + 1
# That colon MUST be followed by a string... # That colon MUST be followed by a string...

View File

@ -543,6 +543,13 @@ async def foo(self):
f'xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}', 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 # output
@ -1221,3 +1228,10 @@ async def foo(self):
f"xxxxxxxxxxxxx xxxx xx xxxxxxxxxx. xxxxx: {x.xxx}" 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"),
}