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

Check for ast.Attributes when finding occurrences in f-strings #751

Merged
merged 5 commits into from
Mar 5, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add tests for occurrences in f-string
  • Loading branch information
lieryan committed Mar 5, 2024
commit 3d2cc6dff3b46570addfa3b86f21c9c87ffad46c
22 changes: 22 additions & 0 deletions ropetest/refactor/renametest.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,28 @@ def test_renaming_occurrence_in_nested_f_string(self):
refactored = self._local_rename(code, 2, "new_var")
self.assertEqual(expected, refactored)

def test_renaming_attribute_occurrences_in_f_string(self):
code = dedent("""\
class MyClass:
def __init__(self):
self.abc = 123

def func(obj):
print(f'{obj.abc}')
return obj.abc
""")
expected = dedent("""\
class MyClass:
def __init__(self):
self.new_var = 123

def func(obj):
print(f'{obj.new_var}')
return obj.new_var
""")
refactored = self._local_rename(code, code.index('abc'), "new_var")
self.assertEqual(expected, refactored)

def test_not_renaming_string_contents_in_f_string(self):
refactored = self._local_rename(
"a_var = 20\na_string=f'{\"a_var\"}'\n", 2, "new_var"
Expand Down