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

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

Closed
zgoda opened this issue Sep 9, 2020 · 3 comments
Closed

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

zgoda opened this issue Sep 9, 2020 · 3 comments
Labels
bug Issue identified by VS Code Team member as probable bug

Comments

@zgoda
Copy link

zgoda commented Sep 9, 2020

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.

@zgoda zgoda added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Sep 9, 2020
@zgoda
Copy link
Author

zgoda commented Sep 9, 2020

This broke with isort 5.5, works fine with 5.4

@falsetru
Copy link

@zgoda, The issue was because of PyCQA/isort#1469. It's solved in isort 5.5.2.

@zgoda
Copy link
Author

zgoda commented Sep 10, 2020

Thanks.

@zgoda zgoda closed this as completed Sep 10, 2020
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 10, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue identified by VS Code Team member as probable bug
Projects
None yet
Development

No branches or pull requests

2 participants