Replies: 1 comment
-
Kinda, but not really... When you use MoveGlobal refactoring, by default rope would change all references of the object to use this import style and there are some configuration to choose between a few different import style. So if you move the variable once and then back again to its original spot, it effectively would do this refactor. Would be good to have a proper mechanism to have a "change import style" refactoring, there's currently no direct way to do this refactoring at the moment. But basically, if you comment out the validation in MoveRefactoring here to disallow moving to the same module and also just remove the call to @@ -342,10 +342,10 @@ class MoveGlobal:
raise exceptions.RefactoringError(
"Move destination for non-modules should not be folders."
)
- if self.source == dest:
- raise exceptions.RefactoringError(
- "Moving global elements to the same module."
- )
+ # if self.source == dest:
+ # raise exceptions.RefactoringError(
+ # "Moving global elements to the same module."
+ # )
return self._calculate_changes(dest, resources, task_handle)
def _calculate_changes(self, dest, resources, task_handle):
@@ -354,7 +354,8 @@ class MoveGlobal:
for file_ in resources:
job_set.started_job(file_.path)
if file_ == self.source:
- changes.add_change(self._source_module_changes(dest))
+ pass
elif file_ == dest:
changes.add_change(self._dest_module_changes(dest))
elif self.tools.occurs_in_module(resource=file_): then you can basically do a "change import style" refactoring by doing a Move Global with destination module being the same as the source module. I think a standalone "change import style" would be quite useful to have. It can be done by combining rename, organize_import, and add_import in a very similar way to what |
Beta Was this translation helpful? Give feedback.
-
I want to refactor this code
to
The second style has some advantages.
cat
along is unclear and unconvinced compared withtorch.cat
, in this case.Is there a way to refactor this import style.
Beta Was this translation helpful? Give feedback.
All reactions