Repository navigation
Refactor variable failing with Rope error 'Extracted piece should contain complete statements' #1568
Copy link
Copy link
Closed
Labels
bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug
Description
Environment data
- VS Code version: 1.22.2
- Extension version (available under the Extensions sidebar): XXX
- OS and version: Windows 8.1
- Python version (& distribution if applicable, e.g. Anaconda): Anaconda 5.1.0, Python 3.6.4
- Type of virtual environment used (N/A | venv | virtualenv | conda | ...): N/A
- Relevant/affected Python packages and their versions: rope 0.10.7
Actual behavior
Possibly a repeat of #52, but I figured I publish it since I'm actually getting error messages.
Code in question is here and screenshots shown below:
Up until this point, no errors and everything is acting normally. Then when I actually type in Team to replace the newvariable###, I get errors and nothing happens
Expected behavior
I expect the variable to extracted and be able to be renamed.
Steps to reproduce:
- Open
main.pyin the repo above - Highlight
driver['Team'], right click, selectExtract Variable - (wait awhile for it to work. takes like 5-10 seconds for it to work)
- Go to type in
Teamto replacenewvariable### - Get nothing but errors
Logs
Output for Python in the Output panel (View→Output, change the drop-down the upper-right of the Output panel to Python)
##########Refactor Output##########
Error in refactoring:
Refactor failed. Extracted piece should contain complete statements.
[<FrameSummary file refactor.py, line 271 in watch>, <FrameSummary file refactor.py, line 256 in _process_request>, <FrameSummary file refactor.py, line 200 in _extractVariable>, <FrameSummary file refactor.py, line 94 in refactor>, <FrameSummary file refactor.py, line 140 in onRefactor>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\extract.py, line 69 in get_changes>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\extract.py, line 213 in __init__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\extract.py, line 350 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\extract.py, line 371 in base_conditions>]
Refactor failed. expected string or bytes-like object
[<FrameSummary file refactor.py, line 271 in watch>, <FrameSummary file refactor.py, line 252 in _process_request>, <FrameSummary file refactor.py, line 183 in _rename>, <FrameSummary file refactor.py, line 94 in refactor>, <FrameSummary file refactor.py, line 116 in onRefactor>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\rename.py, line 101 in get_changes>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\rename.py, line 117 in _is_renaming_a_module>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 22 in get_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynames.py, line 188 in get>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 19 in _get_inferred>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 71 in infer_assigned_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 142 in _infer_assignment>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 175 in _follow_pyname>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 27 in eval_node>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 32 in eval_node2>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\ast.py, line 39 in walk>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 292 in _Subscript>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 303 in _call_function>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 22 in get_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynames.py, line 188 in get>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 19 in _get_inferred>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 71 in infer_assigned_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 142 in _infer_assignment>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 175 in _follow_pyname>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 27 in eval_node>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 32 in eval_node2>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\ast.py, line 39 in walk>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 162 in _Call>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 283 in _get_primary_and_object_for_node>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 32 in eval_node2>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\ast.py, line 39 in walk>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 151 in _Attribute>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 27 in eval_node>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 32 in eval_node2>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\ast.py, line 39 in walk>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 292 in _Subscript>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 303 in _call_function>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 42 in get_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pyobjectsdef.py, line 69 in get_parameter>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynames.py, line 188 in get>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pyobjectsdef.py, line 40 in _infer_parameters>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 47 in infer_parameter_objects>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 130 in _parameter_objects>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\type_hinting\providers\inheritance.py, line 21 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\type_hinting\providers\composite.py, line 19 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\type_hinting\providers\docstrings.py, line 46 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\type_hinting\providers\numpydocstrings.py, line 20 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\numpydoc\docscrape.py, line 123 in __init__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\textwrap.py, line 430 in dedent>]
Output from Console under the Developer Tools panel (toggle Developer Tools on under Help)
Cannot perform refactoring using selected element(s). (Refactor failed. Extracted piece should contain complete statements. [<FrameSummary file refactor.py, line 271 in watch>, <FrameSummary file refactor.py, line 256 in _process_request>, <FrameSummary file refactor.py, line 200 in _extractVariable>, <FrameSummary file refactor.py, line 94 in refactor>, <FrameSummary file refactor.py, line 140 in onRefactor>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\extract.py, line 69 in get_changes>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\extract.py, line 213 in __init__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\extract.py, line 350 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\extract.py, line 371 in base_conditions>])
e.onDidNotificationChange @ /C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.main.js:2217
/C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.main.js:2217 Refactor failed. expected string or bytes-like object [<FrameSummary file refactor.py, line 271 in watch>, <FrameSummary file refactor.py, line 252 in _process_request>, <FrameSummary file refactor.py, line 183 in _rename>, <FrameSummary file refactor.py, line 94 in refactor>, <FrameSummary file refactor.py, line 116 in onRefactor>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\rename.py, line 101 in get_changes>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\rename.py, line 117 in _is_renaming_a_module>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 22 in get_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynames.py, line 188 in get>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in ne...
e.onDidNotificationChange @ /C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.main.js:2217
/C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.main.js:260 [Extension Host] WARNING: Promise with no error callback:3
/C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.main.js:1306 ERR Refactor failed. expected string or bytes-like object
[<FrameSummary file refactor.py, line 271 in watch>, <FrameSummary file refactor.py, line 252 in _process_request>, <FrameSummary file refactor.py, line 183 in _rename>, <FrameSummary file refactor.py, line 94 in refactor>, <FrameSummary file refactor.py, line 116 in onRefactor>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\rename.py, line 101 in get_changes>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\refactor\rename.py, line 117 in _is_renaming_a_module>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 22 in get_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynames.py, line 188 in get>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 19 in _get_inferred>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 71 in infer_assigned_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 142 in _infer_assignment>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 175 in _follow_pyname>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 27 in eval_node>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 32 in eval_node2>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\ast.py, line 39 in walk>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 292 in _Subscript>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 303 in _call_function>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 22 in get_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynames.py, line 188 in get>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 19 in _get_inferred>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 71 in infer_assigned_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 142 in _infer_assignment>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 175 in _follow_pyname>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 27 in eval_node>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 32 in eval_node2>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\ast.py, line 39 in walk>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 162 in _Call>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 283 in _get_primary_and_object_for_node>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 32 in eval_node2>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\ast.py, line 39 in walk>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 151 in _Attribute>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 27 in eval_node>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 32 in eval_node2>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\ast.py, line 39 in walk>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 292 in _Subscript>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\evaluate.py, line 303 in _call_function>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynamesdef.py, line 42 in get_object>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pyobjectsdef.py, line 69 in get_parameter>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 29 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pynames.py, line 188 in get>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\pyobjectsdef.py, line 40 in _infer_parameters>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\utils\__init__.py, line 41 in newfunc>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 47 in infer_parameter_objects>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\soi.py, line 130 in _parameter_objects>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\type_hinting\providers\inheritance.py, line 21 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\type_hinting\providers\composite.py, line 19 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\type_hinting\providers\docstrings.py, line 46 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\rope\base\oi\type_hinting\providers\numpydocstrings.py, line 20 in __call__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\site-packages\numpydoc\docscrape.py, line 123 in __init__>, <FrameSummary file C:\ProgramData\Anaconda3\lib\textwrap.py, line 430 in dedent>]
/C:/Program Files/Microsoft VS Code/resources/app/out/vs/workbench/workbench.main.js:260 [Extension Host]% Object
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugIssue identified by VS Code Team member as probable bugIssue identified by VS Code Team member as probable bug


Activity
d3r3kk commentedon May 2, 2018
Appears to be related to issue #500 perhaps? (I was unable to repro in my non-Anaconda environment)
DonJayamanne commentedon May 2, 2018
The error message returned in #500 is different, hence I'd leave this one open.
brettcannon commentedon May 7, 2018
With this as the code:
I was able to refactor to:
IOW I can't reproduce. @u2berggeist can you include the code for us to directly test against?
jrwrigh commentedon May 9, 2018
I just re-imaged my computer (un related issue), so I'll try and redo it again.
I linked the specific commit in the repo where the code is in the original write up for the issue. Here is the link to the code in question again.
7 remaining items
[-]Refactor variable kinda failed[/-][+]Refactor variable failing with Rope error 'Extracted piece should contain complete statements'[/+]d3r3kk commentedon Jul 31, 2018
I can reproduce this on Python 3.6.6 now. I used this code (replacing your 'f1classes' with a stub):
Where I see error message:
DonJayamanne commentedon Aug 7, 2018
Fyi, the above message is returned by rope when the code is deemed incorrect (invalid syntax). Then again it's possible there's an error in to itself
jrwrigh commentedon Aug 7, 2018
Don Jayamanne (@DonJayamanne) Does that mean that this is probably a
ropeissue instead of avscode-pythonissue?DonJayamanne commentedon Aug 7, 2018
To be determined.
jrwrigh commentedon Nov 13, 2018
For what it's worth, I've noticed that using the
Rename Symbolfunction A) works beautifully and B) is quite fast.I'm ok with closing the
ticketissue if y'all are.