X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/05b63c4bccbfb292a92d3ec962ce9b8fa4ebcfd5..18c17bea757dc88d0b6d2be6e99a4ebcc18e288c:/src/black/trans.py?ds=sidebyside diff --git a/src/black/trans.py b/src/black/trans.py index 01aa80e..28d9250 100644 --- a/src/black/trans.py +++ b/src/black/trans.py @@ -121,7 +121,7 @@ def hug_power_op(line: Line, features: Collection[Feature]) -> Iterator[Line]: return False - leaves: List[Leaf] = [] + new_line = line.clone() should_hug = False for idx, leaf in enumerate(line.leaves): new_leaf = leaf.clone() @@ -139,18 +139,14 @@ def hug_power_op(line: Line, features: Collection[Feature]) -> Iterator[Line]: if should_hug: new_leaf.prefix = "" - leaves.append(new_leaf) - - yield Line( - mode=line.mode, - depth=line.depth, - leaves=leaves, - comments=line.comments, - bracket_tracker=line.bracket_tracker, - inside_brackets=line.inside_brackets, - should_split_rhs=line.should_split_rhs, - magic_trailing_comma=line.magic_trailing_comma, - ) + # We have to be careful to make a new line properly: + # - bracket related metadata must be maintained (handled by Line.append) + # - comments need to copied over, updating the leaf IDs they're attached to + new_line.append(new_leaf, preformatted=True) + for comment_leaf in line.comments_after(leaf): + new_line.append(comment_leaf, preformatted=True) + + yield new_line class StringTransformer(ABC):