rope
rope copied to clipboard
Rename a python class name with a script
Describe the bug
Renaming a python class with rope.refactor.rename
does not update the import statement in other files of the project.
To Reproduce Steps to reproduce the behavior:
- Code before refactoring:
Given the following the project structure
proja
-- __init__.py
-- city.py
-- citycapitol.py
city.py
class City:
pass
citycapitol.py
from pcka.city import City
class CityCapitol(City):
pass
- Describe the refactoring you want to do
import rope.refactor.rename
import rope.refactor.restructure
proj = rope.base.project.Project('pcka')
res = proj.get_module('city').get_resource()
offset = res.read().index(f'class City') + 6
change = rope.refactor.rename.Rename(
proj,
res,
offset,
).get_changes('City2')
print(change.get_description())
- Expected code after refactoring:
city.py
class City2:
pass
citycapitol.py
from pcka.city import City2
class CityCapitol(City2):
pass
- Describe the error or unexpected result that you are getting
The import statement in citycapitol.py
does not get adapted.
citycapitol.py
from pcka.city import City
class CityCapitol(City):
pass
Screenshots
The change.get_description()
returns the following
Renaming <City> to <City2>:
--- a/city.py
+++ b/city.py
@@ -1,2 +1,2 @@
-class City:
+class City2:
pass
Editor information (please complete the following information):
- Project Python version: 3.10.0
- Rope Python version: 0.23.0