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 renaming kwargs when refactoring from imports #646

Merged
merged 2 commits into from
Jan 11, 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
6 changes: 5 additions & 1 deletion rope/refactor/importutils/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,11 @@ def _from_to_normal(self, pymodule, import_stmt):
if alias is not None:
imported = alias
occurrence_finder = occurrences.create_finder(
self.project, imported, pymodule[imported], imports=False
self.project,
imported,
pymodule[imported],
imports=False,
keywords=False,
)
source = rename.rename_in_module(
occurrence_finder,
Expand Down
7 changes: 7 additions & 0 deletions ropetest/refactor/importutilstest.py
Original file line number Diff line number Diff line change
Expand Up @@ -903,6 +903,13 @@ def test_transforming_froms_to_normal_for_os_path(self):
changed_module = self.import_tools.froms_to_imports(pymod)
self.assertEqual("import os\nos.path.exists('.')\n", changed_module)


def test_transforming_froms_to_normal_kwarg_with_same_name(self):
self.mod.write("from os import path\nfoo(path=path.join('a', 'b'))\n")
pymod = self.project.get_pymodule(self.mod)
changed_module = self.import_tools.froms_to_imports(pymod)
self.assertEqual("import os\nfoo(path=os.path.join('a', 'b'))\n", changed_module)

def test_transform_relatives_imports_to_abs_imports_doing_nothing(self):
self.mod2.write("from pkg1 import mod1\nimport mod1\n")
pymod = self.project.get_pymodule(self.mod2)
Expand Down