Commits

Anonymous committed 6c2b497

inline: handling 1-level imported names

  • Participants
  • Parent commits 4252354

Comments (0)

Files changed (1)

File rope/refactor/inline.py

 
     """
     pycore = project.pycore
-    this_pymodule = pycore.resource_to_pyobject(resource)
-    pyname = evaluate.eval_location(this_pymodule, offset)
+    pyname = _get_pyname(pycore, resource, offset)
     message = 'Inline refactoring should be performed on ' \
               'a method, local variable or parameter.'
     if pyname is None:
         raise rope.base.exceptions.RefactoringError(message)
+    if isinstance(pyname, pynames.ImportedName):
+        pyname = pyname._get_imported_pyname()
     if isinstance(pyname, pynames.AssignedName):
         return InlineVariable(project, resource, offset)
     if isinstance(pyname, pynames.ParameterName):
     def __init__(self, project, resource, offset):
         self.project = project
         self.pycore = project.pycore
-        this_pymodule = self.pycore.resource_to_pyobject(resource)
-        self.pyname = evaluate.eval_location(this_pymodule, offset)
+        self.pyname = _get_pyname(self.pycore, resource, offset)
         range_finder = worder.Worder(resource.read())
         self.region = range_finder.get_primary_range(offset)
         self.name = range_finder.get_word_at(offset)
     pymodule = pycore.get_string_module(source, resource)
     import_tools = importutils.ImportTools(pycore)
     return import_tools.organize_imports(pymodule, unused=False, sort=False)
+
+def _get_pyname(pycore, resource, offset):
+    pymodule = pycore.resource_to_pyobject(resource)
+    pyname = evaluate.eval_location(pymodule, offset)
+    if isinstance(pyname, pynames.ImportedName):
+        pyname = pyname._get_imported_pyname()
+    return pyname