Skip to content

Refactor: sort imports fails with "Invalid patch string: import XXX" #13848

@zgoda

Description

@zgoda

Environment data

  • VS Code version: 1.48.2
  • Extension version (available under the Extensions sidebar): 2020.8
  • OS and version: Linux Ubuntu 20.04 x86_64
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.2
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): venv
  • Relevant/affected Python packages and their versions: isort 5.5.1
  • Relevant/affected Python-related VS Code extensions and their versions: XXX
  • Value of the python.languageServer setting: Pylance

Expected behaviour

Invoking "Refactor: sort imports" runs isort and sorts import declarations in current document

Actual behaviour

Zrzut ekranu z 2020-09-09 20-46-13

Steps to reproduce:

  1. install isort in venv
  2. configure workspace to use custom isort
  3. open Python file
  4. invoke "Refactor: sort imports" from command palette

Logs

Output:

Error: Invalid patch string: import ast
Error 2020-09-09 20:35:15: Failed to format imports for '/home/jazg/work/bbbrating/server/setup.py'. [Error: Invalid patch string: import ast
	at n.y (/home/jazg/.vscode/extensions/ms-python.python-2020.8.106424/out/client/extension.js:1:515081)
	at v.getWorkspaceEditsFromPatch (/home/jazg/.vscode/extensions/ms-python.python-2020.8.106424/out/client/extension.js:1:518006)
	at b._provideDocumentSortImportsEdits (/home/jazg/.vscode/extensions/ms-python.python-2020.8.106424/out/client/extension.js:56:895891)
	at processTicksAndRejections (internal/process/task_queues.js:85:5)]

File setup.py begins with

import ast
import codecs

This generally fails on 1st import statement (other imports in other modules).

isort itself works OK and does not produce any error on this file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions