rope icon indicating copy to clipboard operation
rope copied to clipboard

exception when refactoring method of class defined in function

Open julian-goettingen opened this issue 2 years ago • 0 comments

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:

  1. Code before refactoring:
def function_defining_class():

    class Inner:
        def __init__(self, logger):
            self.logger = logger

    return Inner('logger')
  1. Remove Argument logger of init in Inner

  2. Expected code after refactoring:

def function_defining_class():

    class Inner:
        def __init__(self):
            self.logger = logger

    return Inner()
  1. 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)

julian-goettingen avatar May 30 '23 12:05 julian-goettingen