diff --git a/rope/base/codeanalyze.py b/rope/base/codeanalyze.py index d8b8da086..6f2e35d2b 100644 --- a/rope/base/codeanalyze.py +++ b/rope/base/codeanalyze.py @@ -524,7 +524,7 @@ def get_formatted_string_pattern(): def get_any_string_pattern(): - prefix = r"[bBfFrRuU]{,4}" + prefix = r"[bBfFrRuUtT]{,4}" return get_string_pattern_with_prefix( prefix, prefix_group_name="prefix", diff --git a/rope/base/simplify.py b/rope/base/simplify.py index 3198c26de..45f5f0d81 100644 --- a/rope/base/simplify.py +++ b/rope/base/simplify.py @@ -26,7 +26,10 @@ def real_code(source): for start, end, matchgroups in ignored_regions(source): if source[start] == "#": replacement = " " * (end - start) - elif "f" in matchgroups.get("prefix", "").lower(): + elif any( + prefix in matchgroups.get("prefix", "").lower() + for prefix in ("f", "t") + ): replacement = None else: replacement = '"%s"' % (" " * (end - start - 2)) diff --git a/ropetest/refactor/renametest.py b/ropetest/refactor/renametest.py index 9303fb15b..96a71a21a 100644 --- a/ropetest/refactor/renametest.py +++ b/ropetest/refactor/renametest.py @@ -319,6 +319,12 @@ def test_renaming_occurrence_in_f_string(self): refactored = self._local_rename(code, 2, "new_var") self.assertEqual(expected, refactored) + def test_renaming_occurrence_in_t_string(self): + code = 'a = 20\na_string = f(t"{a}(", ")")\n' + expected = 'new_var = 20\na_string = f(t"{new_var}(", ")")\n' + refactored = self._local_rename(code, 0, "new_var") + self.assertEqual(expected, refactored) + def test_renaming_occurrence_in_nested_f_string(self): code = dedent("""\ a_var = 20