diff --git a/rope/refactor/patchedast.py b/rope/refactor/patchedast.py index 614ea51b1..f7882e232 100644 --- a/rope/refactor/patchedast.py +++ b/rope/refactor/patchedast.py @@ -903,6 +903,16 @@ def _MatchClass(self, node): def _MatchValue(self, node): self._handle(node, [node.value]) + def _MatchMapping(self, node): + children = [] + children.append("{") + for index, (key, value) in enumerate(zip(node.keys, node.patterns)): + children.extend([key, ":", value]) + if index < len(node.keys) - 1: + children.append(",") + children.append("}") + self._handle(node, children) + class _Source: def __init__(self, source): diff --git a/ropetest/refactor/patchedasttest.py b/ropetest/refactor/patchedasttest.py index 0db04e463..bcfe482c2 100644 --- a/ropetest/refactor/patchedasttest.py +++ b/ropetest/refactor/patchedasttest.py @@ -1565,6 +1565,36 @@ def test_match_node_with_match_class_match_as_capture_pattern_with_explicit_name ]) + @testutils.only_for_versions_higher("3.10") + def test_match_node_with_match_mapping_match_as(self): + source = dedent("""\ + match x: + case {"a": b} as c: + print(x) + """) + ast_frag = patchedast.get_patched_ast(source, True) + checker = _ResultChecker(self, ast_frag) + self.assert_single_case_match_block(checker, "MatchAs") + checker.check_children("MatchAs", [ + "MatchMapping", + " ", + "as", + " ", + "c", + ]) + checker.check_children("MatchMapping", [ + "{", + "", + "Constant", + "", + ":", + " ", + "MatchAs", + "", + "}", + ]) + + class _ResultChecker: def __init__(self, test_case, ast): self.test_case = test_case