rope
rope copied to clipboard
Extract method not working for files outside of the folder if the line contain `self.`
Steps to reproduce
- Create a file and save it to the parent directory (outside of the project folder):
class my_class():
def my_method(self):
self.var = 1
- Select the last line
- Press right mouse button and choose "Extract method"
Current behavior
The error raised (looks like rope looking for a module named as a parent directory):
Traceback
Traceback (most recent call last):
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/pylsp_rope/plugin.py", line 152, in pylsp_execute_command
return commands[command](workspace, **arguments[0])()
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/pylsp_rope/plugin.py", line 176, in __call__
rope_changeset = self.get_changes()
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/pylsp_rope/plugin.py", line 240, in get_changes
rope_changeset = refactoring.get_changes(
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/extract.py", line 83, in get_changes
new_contents = _ExtractPerformer(info).extract()
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/extract.py", line 288, in extract
extract_info = self._collect_info()
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/extract.py", line 315, in _collect_info
self._find_matches(extract_collector)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/extract.py", line 329, in _find_matches
for region_match in region_matches:
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 106, in get_matches
for match in self._get_matched_asts(code):
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 116, in _get_matched_asts
matches = _ASTMatcher(self.ast, wanted, self.does_match).find_matches()
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 157, in find_matches
ast.call_for_nodes(self.body, self._check_node, recursive=True)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/base/ast.py", line 65, in call_for_nodes
call_for_nodes(child, callback, recursive)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/base/ast.py", line 65, in call_for_nodes
call_for_nodes(child, callback, recursive)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/base/ast.py", line 62, in call_for_nodes
result = callback(node)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 162, in _check_node
self._check_statements(node)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 174, in _check_statements
self.__check_stmt_list(child)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 181, in __check_stmt_list
if self._match_stmts(current_stmts, mapping):
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 221, in _match_stmts
if not self._match_nodes(expected, stmt, mapping):
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 205, in _match_nodes
if not self._match_nodes(c1, c2, mapping):
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 199, in _match_nodes
if not self._match_nodes(child1, child2, mapping):
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 187, in _match_nodes
return self._match_wildcard(expected, node, mapping)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 228, in _match_wildcard
if self.matches_callback(node2, name):
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/similarfinder.py", line 66, in _does_match
return self.wildcards[kind].matches(suspect, arg)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/wildcards.py", line 46, in matches
if not self._check_object(args, suspect):
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/wildcards.py", line 59, in _check_object
checker = _CheckObject(self.project, expected, kind, unsure=unsure)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/wildcards.py", line 93, in __init__
self.expected = self._evaluate(expected)
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/refactor/wildcards.py", line 169, in _evaluate
pyobject = self.project.get_module(attributes[0])
File "/home/lieryan/.virtualenvs/supercloud-dashboard-6A_4T29Q-py3.10/lib/python3.10/site-packages/rope/base/project.py", line 60, in get_module
raise ModuleNotFoundError("Module %s not found" % name)
rope.base.exceptions.ModuleNotFoundError: Module outfile not found
Original traceback
Cannot perform refactoring using selected element(s). (Refactor failed. Module Colab Notebooks not found [<FrameSummary file c:\Users\FA.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\refactor.py, line 380 in watch>, <FrameSummary file c:\Users\FA.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\refactor.py, line 368 in _process_request>, <FrameSummary file c:\Users\FA.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\refactor.py, line 313 in _extractMethod>, <FrameSummary file c:\Users\FA.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\refactor.py, line 128 in refactor>, <FrameSummary file c:\Users\FA.vscode\extensions\ms-python.python-2020.12.424452561\pythonFiles\refactor.py, line 230 in onRefactor>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\extract.py, line 69 in get_changes>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\extract.py, line 216 in extract>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\extract.py, line 245 in _collect_info>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\extract.py, line 258 in _find_matches>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 101 in get_matches>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 113 in _get_matched_asts>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 155 in find_matches>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\base\ast.py, line 66 in call_for_nodes>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\base\ast.py, line 66 in call_for_nodes>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\base\ast.py, line 63 in call_for_nodes>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 160 in _check_node>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 172 in _check_statements>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 179 in __check_stmt_list>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 221 in _match_stmts>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 204 in _match_nodes>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 197 in _match_nodes>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 185 in _match_nodes>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 228 in _match_wildcard>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\similarfinder.py, line 65 in _does_match>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\wildcards.py, line 48 in matches>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\wildcards.py, line 62 in _check_object>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\wildcards.py, line 97 in init>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\refactor\wildcards.py, line 172 in _evaluate>, <FrameSummary file C:\Users\FA\AppData\Roaming\Python\Python36\site-packages\rope\base\project.py, line 59 in get_module>])
Expected behavior:
no error