Skip to content

Commit 17a171f

Browse files
committed
Fix multiline empty tuple with comment
1 parent 54433b8 commit 17a171f

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

rope/refactor/patchedast.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,9 @@ def consume_number(self):
874874
return self._consume_pattern(repattern)
875875

876876
def consume_empty_tuple(self):
877-
return self._consume_pattern(re.compile(r"\(\s*\)"))
877+
s, _ = self.consume("(")
878+
_, e = self.consume(")")
879+
return (s, e)
878880

879881
def consume_with_or_comma_context_manager(self):
880882
repattern = re.compile(r"with|,")

ropetest/refactor/patchedasttest.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ def test_tuple_with_complex_parentheses1(self):
10001000
ast_frag = patchedast.get_patched_ast(source, True)
10011001
checker = _ResultChecker(self, ast_frag)
10021002
checker.check_children(
1003-
"Tuple", ["(", "", "Tuple", "", ",", " ", NameConstant, "", ")"]
1003+
"Tuple", ["Tuple", "", ",", " ", NameConstant]
10041004
)
10051005

10061006
def test_tuple_with_complex_parentheses2(self):
@@ -1016,7 +1016,7 @@ def test_tuple_with_complex_parentheses3(self):
10161016
ast_frag = patchedast.get_patched_ast(source, True)
10171017
checker = _ResultChecker(self, ast_frag)
10181018
checker.check_children(
1019-
"Tuple", ["(", "", "Tuple", "", ",", " ", "Tuple", ",", ")"]
1019+
"Tuple", ["Tuple", "", ",", " ", "Tuple"]
10201020
)
10211021

10221022
def test_one_item_tuple_node(self):
@@ -1036,7 +1036,7 @@ def test_empty_tuple_node2(self):
10361036
ast_frag = patchedast.get_patched_ast(source, True)
10371037
checker = _ResultChecker(self, ast_frag)
10381038
checker.check_children(
1039-
"Tuple", ["(", "", "Tuple", "", ",", " ", NameConstant, "", ")"]
1039+
"Tuple", ["Tuple", "", ",", " ", NameConstant]
10401040
)
10411041

10421042
def test_empty_tuple_node3(self):
@@ -1047,6 +1047,12 @@ def test_empty_tuple_node3(self):
10471047
"Tuple", ["Tuple", "", ",", " ", NameConstant]
10481048
)
10491049

1050+
def test_empty_tuple_node4(self):
1051+
source = "a = (\n# foo,\n)\n"
1052+
ast_frag = patchedast.get_patched_ast(source, True)
1053+
checker = _ResultChecker(self, ast_frag)
1054+
checker.check_children("Tuple", ["(\n# foo,\n)"])
1055+
10501056
def test_yield_node(self):
10511057
source = dedent("""\
10521058
def f():
@@ -1575,6 +1581,8 @@ def check_children(self, text, children):
15751581
if node is None:
15761582
self.test_case.fail("Node <%s> cannot be found" % text)
15771583
result = list(node.sorted_children)
1584+
print(children)
1585+
print(result)
15781586
self.test_case.assertEqual(len(children), len(result))
15791587
for expected, child in zip(children, result):
15801588
goals = expected

0 commit comments

Comments
 (0)