Skip to content

Commit

Permalink
Handle match_case in line_range as it is missing lineno
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmojaki committed Oct 29, 2022
1 parent f24abe7 commit 54fb67d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions stack_data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ def line_range(atok: ASTText, node: ast.AST) -> Tuple[int, int]:
(i.e. suitable as arguments to the `range()` builtin)
of line numbers of the given AST nodes.
"""
start, end = atok.get_text_positions(node, padded=False)
return start[0], end[0] + 1
if isinstance(node, getattr(ast, "match_case", ())):
start, _end = line_range(atok, node.pattern)
_start, end = line_range(atok, node.body[-1])
return start, end
else:
(start, _), (end, _) = atok.get_text_positions(node, padded=False)
return start, end + 1


def highlight_unique(lst: List[T]) -> Iterator[Tuple[T, bool]]:
Expand Down

0 comments on commit 54fb67d

Please sign in to comment.