rope
rope copied to clipboard
exception when refactoring method of class defined in function
Describe the bug When using the ArgumentRemover-refactoring on a class defined not at the top level I am getting an AttributeNotFoundError from within the library
To Reproduce Steps to reproduce the behavior:
- Code before refactoring:
def function_defining_class():
class Inner:
def __init__(self, logger):
self.logger = logger
return Inner('logger')
-
Remove Argument logger of init in Inner
-
Expected code after refactoring:
def function_defining_class():
class Inner:
def __init__(self):
self.logger = logger
return Inner()
- Describe the error or unexpected result that you are getting
...
File "C:\Users\username\rope_playground\refactor.py", line 83, in do_file
signature = change_signature.ChangeSignature(proj, resource, start+4)
File "C:\Users\username\AppData\Roaming\Python\Python310\site-packages\rope\refactor\change_signature.py", line 14, in __init__
self._set_name_and_pyname()
File "C:\Users\username\AppData\Roaming\Python\Python310\site-packages\rope\refactor\change_signature.py", line 42, in _set_name_and_pyname
self.others = (pyclass.get_name(), pyclass.parent[pyclass.get_name()])
File "C:\Users\username\AppData\Roaming\Python\Python310\site-packages\rope\base\pyobjects.py", line 30, in __getitem__
return self.get_attribute(key)
File "C:\Users\username\AppData\Roaming\Python\Python310\site-packages\rope\base\pyobjects.py", line 218, in get_attribute
raise exceptions.AttributeNotFoundError("Attribute %s not found" % name)
rope.base.exceptions.AttributeNotFoundError: Attribute Inner not found
Editor information (please complete the following information):
- Project Python version: 3.7.9
- Rope Python version: 3.7.9
- Rope version: 1.8.0
- Text editor/IDE and version: (no editor, using as a library)
Additional context (I know the 'expected code' would not run correctly but I know the Remove-Argument-refactoring does not modify the function body so I do not expect that to happen here either)