From 17a171f1dc3edf8af71ebeb50abfddf5cbb00682 Mon Sep 17 00:00:00 2001 From: Austin Morton Date: Wed, 1 May 2024 02:35:51 +0000 Subject: [PATCH] Fix multiline empty tuple with comment --- rope/refactor/patchedast.py | 4 +++- ropetest/refactor/patchedasttest.py | 14 +++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/rope/refactor/patchedast.py b/rope/refactor/patchedast.py index 4e842c046..6a17445c1 100644 --- a/rope/refactor/patchedast.py +++ b/rope/refactor/patchedast.py @@ -874,7 +874,9 @@ def consume_number(self): return self._consume_pattern(repattern) def consume_empty_tuple(self): - return self._consume_pattern(re.compile(r"\(\s*\)")) + s, _ = self.consume("(") + _, e = self.consume(")") + return (s, e) def consume_with_or_comma_context_manager(self): repattern = re.compile(r"with|,") diff --git a/ropetest/refactor/patchedasttest.py b/ropetest/refactor/patchedasttest.py index 3ac341f25..3a1b9ce1f 100644 --- a/ropetest/refactor/patchedasttest.py +++ b/ropetest/refactor/patchedasttest.py @@ -1000,7 +1000,7 @@ def test_tuple_with_complex_parentheses1(self): ast_frag = patchedast.get_patched_ast(source, True) checker = _ResultChecker(self, ast_frag) checker.check_children( - "Tuple", ["(", "", "Tuple", "", ",", " ", NameConstant, "", ")"] + "Tuple", ["Tuple", "", ",", " ", NameConstant] ) def test_tuple_with_complex_parentheses2(self): @@ -1016,7 +1016,7 @@ def test_tuple_with_complex_parentheses3(self): ast_frag = patchedast.get_patched_ast(source, True) checker = _ResultChecker(self, ast_frag) checker.check_children( - "Tuple", ["(", "", "Tuple", "", ",", " ", "Tuple", ",", ")"] + "Tuple", ["Tuple", "", ",", " ", "Tuple"] ) def test_one_item_tuple_node(self): @@ -1036,7 +1036,7 @@ def test_empty_tuple_node2(self): ast_frag = patchedast.get_patched_ast(source, True) checker = _ResultChecker(self, ast_frag) checker.check_children( - "Tuple", ["(", "", "Tuple", "", ",", " ", NameConstant, "", ")"] + "Tuple", ["Tuple", "", ",", " ", NameConstant] ) def test_empty_tuple_node3(self): @@ -1047,6 +1047,12 @@ def test_empty_tuple_node3(self): "Tuple", ["Tuple", "", ",", " ", NameConstant] ) + def test_empty_tuple_node4(self): + source = "a = (\n# foo,\n)\n" + ast_frag = patchedast.get_patched_ast(source, True) + checker = _ResultChecker(self, ast_frag) + checker.check_children("Tuple", ["(\n# foo,\n)"]) + def test_yield_node(self): source = dedent("""\ def f(): @@ -1575,6 +1581,8 @@ def check_children(self, text, children): if node is None: self.test_case.fail("Node <%s> cannot be found" % text) result = list(node.sorted_children) + print(children) + print(result) self.test_case.assertEqual(len(children), len(result)) for expected, child in zip(children, result): goals = expected