diff --git a/rope/refactor/patchedast.py b/rope/refactor/patchedast.py index 4e842c04..6a17445c 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 3ac341f2..0076a338 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():