Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python Refactor: Sort Imports provides inaccurate Error message when skipping __init__.py #2435

Closed
SLAPaper opened this issue Aug 23, 2018 · 10 comments
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug

Comments

@SLAPaper
Copy link

SLAPaper commented Aug 23, 2018

Environment 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"

code_2018-08-23_13-00-45

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:

  1. Ctrl+P, and run "Python Refactor: Sort Imports"

Logs

Output for Python in the Output panel (ViewOutput, 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):
PyCQA/isort@985fd9a#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.

@brettcannon brettcannon added bug Issue identified by VS Code Team member as probable bug area-formatting upstream-isort labels Aug 23, 2018
@brettcannon
Copy link
Member

Since the error message isn't coming from us, this is considered an upstream bug. But I will leave this open to remind us to update to a new release of isort once it comes out.

@AndreasBackx
Copy link

AndreasBackx commented Apr 1, 2019

@brettcannon could the isort version be upgraded so the default value of the argument does not include __init__.py? There have been multiple new versions of isort since that commit that must've included the change, no?

@brettcannon
Copy link
Member

@AndreasBackx no clue if there's a fix, but we can look at upgrading the copy we pull down.

@dustinmichels
Copy link

I too seem to always get the message "Error: Invalid patch string: Skipped 1 files" when running Sort Imports on an __init__.py file.

  • VS Code: Version 1.33.1 (1.33.1)
  • Python: 3.7.2
  • Python extension: Version: 2019.3.6558

@brettcannon
Copy link
Member

@AndreasBackx @dustinmichels we just upgraded isort in our insiders build of the extension. Could either of you give it a try and see if it fixes your problem?

@brettcannon brettcannon added the info-needed Issue requires more information from poster label Apr 17, 2019
@AndreasBackx
Copy link

@brettcannon how could I test that insiders build? I cannot find any information on this repo regarding that.

@brettcannon
Copy link
Member

@AndreasBackx https://github.com/Microsoft/vscode-python/blob/master/CONTRIBUTING.md#development-build

@dustinmichels
Copy link

That seems to work for me!

@AndreasBackx
Copy link

@brettcannon I guess I skimmed over it, thinking it was for developers. I can test it when I have the time Friday if you still want me to. Though I think it's a trivial update and if it works for @dustinmichels, it should be fine.

@brettcannon
Copy link
Member

@AndreasBackx closing as fixed then!

@ghost ghost removed info-needed Issue requires more information from poster needs upstream fix labels Apr 22, 2019
@lock lock bot locked as resolved and limited conversation to collaborators May 20, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-formatting bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

4 participants