Skip to content

Commit

Permalink
Adopt parentless comments
Browse files Browse the repository at this point in the history
Since the id of the old leaf may be
the key to comments, the new leaf
must adopt the old comments
  • Loading branch information
spagh-eddie committed Oct 1, 2023
1 parent d676664 commit 18e4b29
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/black/trans.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down

0 comments on commit 18e4b29

Please sign in to comment.