Ali Gholami Rudi  committed 0a221a7

inline: removing old from imports only when removing the definition

  • Participants
  • Parent commits 28feefa

Comments (0)

Files changed (1)

File rope/refactor/

                 if result is not None:
                     result = _add_imports(self.pycore, result,
                                           file, self.imports)
-                    result = _remove_from(self.pycore, self.pyname,
-                                          result, file)
+                    if remove:
+                        result = _remove_from(self.pycore, self.pyname,
+                                              result, file)
                     changes.add_change(ChangeContents(file, result))
         return changes
                 source = self._change_main_module(remove, only_current)
                 changes.add_change(ChangeContents(self.resource, source))
-                result = self._change_module(resource, only_current)
+                result = self._change_module(resource, remove, only_current)
                 if result is not None:
                     result = _add_imports(self.pycore, result,
                                           resource, self.imports)
         self.imported, self.imports = move.moving_code_with_imports(
             self.pycore, self.resource, vardef)
-    def _change_module(self, resource, only_current):
+    def _change_module(self, resource, remove, only_current):
         filters = [occurrences.NoImportsFilter(),
         if only_current and resource == self.original:
         finder = occurrences.Finder(self.pycore,, filters=filters)
         changed = rename.rename_in_module(
             finder, self.imported, resource=resource, replace_primary=True)
-        if changed:
+        if changed and remove:
             changed = _remove_from(self.pycore, self.pyname, changed, resource)
         return changed