Anonymous committed 0a221a7

inline: removing old from imports only when removing the definition

Comments (0)

Files changed (1)


                 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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.