Skip to content

Commit

Permalink
Fix multiline empty tuple with comment
Browse files Browse the repository at this point in the history
  • Loading branch information
apmorton committed May 1, 2024
1 parent 54433b8 commit 17a171f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 3 additions & 1 deletion rope/refactor/patchedast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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|,")
Expand Down
14 changes: 11 additions & 3 deletions ropetest/refactor/patchedasttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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):
Expand All @@ -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):
Expand All @@ -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():
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 17a171f

Please sign in to comment.