question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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): 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:closed
  • Created 5 years ago
  • Reactions:4
  • Comments:10 (5 by maintainers)

github_iconTop GitHub Comments

3reactions
brettcannoncommented, Apr 1, 2019

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python import: Advanced Techniques and Tips
Using imports properly will make you more productive, allowing you to reuse code while keeping your projects maintainable. This tutorial will provide a...
Read more >
python - How to ignore Pyflakes errors 'imported but unused ...
Show activity on this post. However running Pyflakes on the command-line: pyflakes . It isn't an error, it's just information that you have...
Read more >
Mypy Documentation - Read the Docs
However, if you try directly running mypy on your existing Python code, ... core/config.py:7: error: Cannot find implementation or library ...
Read more >
How to create a Python Package with __init__.py
So, without creating a package and using __init__.py , how do we use the functions in these files? Well, we can only import...
Read more >
How to make mistakes in Python - O'Reilly
There are a couple of ways I've gotten off on the wrong foot by ... The error is even more confusing if the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found