Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix multiline empty tuple with comment #790

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
12 changes: 9 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
Loading