Fix comments getting removed from inside parenthesized strings (#3909)
Since the id of the old leaf may be the key to comments, the new leaf must adopt the old comments
This commit is contained in:
parent
e7c3368c13
commit
a91eb73064
@ -17,6 +17,8 @@
|
||||
|
||||
<!-- Changes that affect Black's preview style -->
|
||||
|
||||
- Fix comments getting removed from inside parenthesized strings (#3909)
|
||||
|
||||
### Configuration
|
||||
|
||||
<!-- Changes to how Black can be configured -->
|
||||
|
@ -942,6 +942,9 @@ def _transform_to_new_line(
|
||||
LL[lpar_or_rpar_idx].remove() # Remove lpar.
|
||||
replace_child(LL[idx], string_leaf)
|
||||
new_line.append(string_leaf)
|
||||
# replace comments
|
||||
old_comments = new_line.comments.pop(id(LL[idx]), [])
|
||||
new_line.comments.setdefault(id(string_leaf), []).extend(old_comments)
|
||||
else:
|
||||
LL[lpar_or_rpar_idx].remove() # This is a rpar.
|
||||
|
||||
|
@ -131,6 +131,18 @@ def test_fails_invalid_post_data(
|
||||
|
||||
square = Square(4) # type: Optional[Square]
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3756.
|
||||
[
|
||||
(
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
),
|
||||
]
|
||||
[
|
||||
( # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
),
|
||||
]
|
||||
|
||||
# output
|
||||
|
||||
from .config import (
|
||||
@ -282,3 +294,15 @@ def test_fails_invalid_post_data(
|
||||
|
||||
|
||||
square = Square(4) # type: Optional[Square]
|
||||
|
||||
# Regression test for https://github.com/psf/black/issues/3756.
|
||||
[
|
||||
( # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
|
||||
),
|
||||
]
|
||||
[
|
||||
( # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa" # aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
|
||||
),
|
||||
]
|
||||
|
Loading…
Reference in New Issue
Block a user