Skip to content
This repository was archived by the owner on Jan 13, 2026. It is now read-only.

Commit cb76242

Browse files
committed
Slightly better pattern matching support
1 parent 93bef83 commit cb76242

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

rewrite/rewrite/python/_parser_visitor.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -835,11 +835,11 @@ def visit_match_case(self, node):
835835
pattern_prefix = self.__whitespace()
836836

837837
pattern = self.__convert(node.pattern)
838-
# if isinstance(pattern, py.MatchCase):
839-
# guard = self.__pad_left(self.__source_before('if'), self.__convert(node.guard))
840-
# pattern = pattern.padding.with_guard(guard)
838+
if isinstance(pattern, py.MatchCase) and node.guard:
839+
guard = self.__pad_left(self.__source_before('if'), self.__convert(node.guard))
840+
pattern = pattern.padding.with_guard(guard)
841841

842-
case = j.Case(
842+
return j.Case(
843843
random_id(),
844844
prefix,
845845
Markers.EMPTY,
@@ -852,7 +852,6 @@ def visit_match_case(self, node):
852852
JContainer.empty(),
853853
self.__pad_right(self.__convert_block(node.body), Space.EMPTY)
854854
)
855-
return case
856855

857856
def visit_MatchValue(self, node):
858857
return self.__convert(node.value)
@@ -990,8 +989,6 @@ def visit_MatchAs(self, node):
990989
None,
991990
None
992991
)
993-
elif node.name is not None and node.pattern is not None:
994-
return self.__convert_name(node.name)
995992
else:
996993
return py.MatchCase(
997994
random_id(),

0 commit comments

Comments
 (0)