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 fstrings with mismatched parens #643

Merged
merged 2 commits into from
Jan 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion rope/refactor/patchedast.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ def _handle(self, node, base_children, eat_parens=False, eat_spaces=False):
child = self.source[region[0] : region[1]]
token_start = region[0]
if not first_token:
formats.append(self.source[offset:token_start])
if not isinstance(node, ast.JoinedStr):
formats.append(self.source[offset:token_start])
if self.children:
children.append(self.source[offset:token_start])
else:
Expand Down
6 changes: 6 additions & 0 deletions ropetest/refactor/patchedasttest.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,12 @@ def test_handling_strings(self):
checker = _ResultChecker(self, ast_frag)
checker.check_children("BinOp", ["Num", " ", "+", " ", "Str"])

def test_handling_fstrings(self):
source = '1 + f"("\n'
ast_frag = patchedast.get_patched_ast(source, True)
checker = _ResultChecker(self, ast_frag)
checker.check_children("BinOp", ["Num", " ", "+", " ", "JoinedStr"])

def test_handling_implicit_string_concatenation(self):
source = "a = '1''2'"
ast_frag = patchedast.get_patched_ast(source, True)
Expand Down