Skip to content

Commit

Permalink
Fix another corner case (psf#3682)
Browse files Browse the repository at this point in the history
Here we enable the backtracking to reach preceding leafs even outside the same parent. As long as they are on the same line, it should be fine, as  is supposed to target the whole line.
  • Loading branch information
henriholopainen committed Oct 26, 2023
1 parent 71ca016 commit d232f7b
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions src/black/comments.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,9 +315,16 @@ def _generate_ignored_nodes_from_fmt_skip(
siblings: List[LN] = []
lineno = prev_sibling.get_lineno()
# We only want siblings from the same line, as fmt: skip targets a line
while prev_sibling is not None and prev_sibling.get_lineno() == lineno:
while (
prev_sibling is not None
and prev_sibling.type not in WHITESPACE
and prev_sibling.get_lineno() == lineno
):
siblings.insert(0, prev_sibling)
prev_sibling = prev_sibling.prev_sibling
preceding = preceding_leaf(prev_sibling)
prev = prev_sibling.prev_sibling
prev_sibling = preceding if prev is None else prev

yield from siblings
elif (
parent is not None and parent.type == syms.suite and leaf.type == token.NEWLINE
Expand Down

0 comments on commit d232f7b

Please sign in to comment.