Refactor variable failing with Rope error 'Extracted piece should contain complete statements'
See original GitHub issueEnvironment 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.py
in 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
Team
to 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
Issue Analytics
- State:
- Created 5 years ago
- Comments:11 (1 by maintainers)
Top Results From Across the Web
"Extract variable/method" consistently throws "Error in ... - GitHub
The error message says "Extracted piece should contain complete statements", despite the confusing exception traceback.
Read more >vscode python refactor failed - Stack Overflow
It doesn't work because Rope has some bugs in it. If you install Pylance then you may have better success (it will automatically...
Read more >Extract method | PyCharm Documentation - JetBrains
The Extract Method refactoring lets you take a code fragment that can be grouped, move it into a separated method, and replace the...
Read more >IDE Features — Elpy 1.35.0 documentation
Set or change the value of a project-wide variable. With a prefix argument, the value for the variable is removed. This only takes...
Read more >Strategies for Learning from Failure - Harvard Business Review
Indeed, tolerance is essential for any organization that wishes to extract the knowledge such failures provide. But failure is still inherently emotionally ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
For what it’s worth, I’ve noticed that using the
Rename Symbol
function A) works beautifully and B) is quite fast.I’m ok with closing the ~ticket~ issue if y’all are.
To be determined.