Python Refactor: Sort Imports provides inaccurate Error message when skipping `__init__.py`
See original GitHub issueEnvironment data
- VS Code version: 1.26.1
- Extension version (available under the Extensions sidebar): Python 2018.7.1
- OS and version: Windows 10 1803 Build 17134.228
- Python version (& distribution if applicable, e.g. Anaconda): Anaconda Python 3.7.0
- Type of virtual environment used (N/A | venv | virtualenv | conda | …): conda
- Relevant/affected Python packages and their versions: isort 4.3.4
Actual behavior
“Python Refactor: Sort Imports” will skip __init__.py
file, and produce an error of “Error: Invalid patch string: Skipped 1 files”
Expected behavior
Should sort the file (not skipping it), or produce an informative instruction about skipping files, not an Error of “Invalid patch string”.
Steps to reproduce:
- Ctrl+P, and run “Python Refactor: Sort Imports”
Logs
Output for Python
in the Output
panel (View
→Output
, change the drop-down the upper-right of the Output
panel to Python
)
Error: Invalid patch string: Skipped 1 files
Output from Console
under the Developer Tools
panel (toggle Developer Tools on under Help
)
Invalid patch string: Skipped 1 files
t.onDidNotificationChange @ workbench.main.js:sourcemap:2386
(anonymous) @ workbench.main.js:sourcemap:2385
e.fire @ workbench.main.js:sourcemap:172
t.notify @ workbench.main.js:sourcemap:2379
t.notify @ workbench.main.js:sourcemap:3458
e._showMessage @ workbench.main.js:sourcemap:3173
e._showMessage @ workbench.main.js:sourcemap:3173
e.$showMessage @ workbench.main.js:sourcemap:3173
e._doInvokeHandler @ workbench.main.js:sourcemap:3204
e._invokeHandler @ workbench.main.js:sourcemap:3204
e._receiveRequest @ workbench.main.js:sourcemap:3203
e._receiveOneMessage @ workbench.main.js:sourcemap:3203
(anonymous) @ workbench.main.js:sourcemap:3202
(anonymous) @ workbench.main.js:sourcemap:3205
e.fire @ workbench.main.js:sourcemap:172
a @ workbench.main.js:sourcemap:307
n._socketDataListener @ workbench.main.js:sourcemap:307
emitOne @ events.js:116
emit @ events.js:211
addChunk @ _stream_readable.js:263
readableAddChunk @ _stream_readable.js:250
Readable.push @ _stream_readable.js:208
onread @ net.js:594
workbench.main.js:sourcemap:1398 ERR Invalid patch string: Skipped 1 files: Error: Invalid patch string: Skipped 1 files
at diff_match_patch.patch_fromText (C:\Users\slapa\.vscode\extensions\ms-python.python-2018.7.1\out\client\common\editor.js:234:19)
at Object.getTextEditsFromPatch (C:\Users\slapa\.vscode\extensions\ms-python.python-2018.7.1\out\client\common\editor.js:51:36)
at PythonImportSortProvider.<anonymous> (C:\Users\slapa\.vscode\extensions\ms-python.python-2018.7.1\out\client\providers\importSortProvider.js:57:33)
at Generator.next (<anonymous>)
at fulfilled (C:\Users\slapa\.vscode\extensions\ms-python.python-2018.7.1\out\client\providers\importSortProvider.js:10:58)
at <anonymous>
Discussion
Upstream isort
have already update the default setting to remove skipping "__init__.py"
(but not release yet):
https://github.com/timothycrosley/isort/commit/985fd9a1718f07a5e14f971139be34a2d9644cb5#diff-57121582b6fc41e2d3a0776d1ddc59d9L50
This use case can be workaround by appending "-ns", "__init__.py"
to "python.sortImports.args"
, but the problem of inaccurate error message may still occur when user define other ignored files.
Issue Analytics
- State:
- Created 5 years ago
- Reactions:4
- Comments:10 (5 by maintainers)
Top GitHub Comments
@AndreasBackx no clue if there’s a fix, but we can look at upgrading the copy we pull down.
@AndreasBackx https://github.com/Microsoft/vscode-python/blob/master/CONTRIBUTING.md#development-build