Skip to content

Commit

Permalink
Merge pull request #643 from apmorton/am/fix-f-string-mismatched-paren
Browse files Browse the repository at this point in the history
Fix fstrings with mismatched parens
  • Loading branch information
lieryan committed Jan 10, 2023
2 parents 52d8de8 + 5c09571 commit 5a347f8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
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

0 comments on commit 5a347f8

Please sign in to comment.