Skip to content

Wrong order in import when using sort imports in vscode #14254

@lfrodrigues

Description

@lfrodrigues

Sorting using the Python Refactor: Sort Imports doesn't generate a correct output.
When I run the same command in the console the output is correct.

Environment data

  • VS Code version: 1.49.0
  • Extension version (available under the Extensions sidebar): v2020.9.112786
  • OS and version: Ubuntu 18.04
  • Python version (& distribution if applicable, e.g. Anaconda): Python 3.6
  • Type of virtual environment used (N/A | venv | virtualenv | conda | ...): virtualenv
  • Value of the python.languageServer setting: Pylance

Expected behaviour

When I sort in the console:

~/Development/virtual_env/bin/python ~/.vscode/extensions/ms-python.python-2020.9.112786/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.9.112786/pythonFiles/sortImports.py src/accounting/lms/utils/xero/book_gt_bank.py

I get:

from datetime import date, datetime
from typing import List

import pytz
from django.conf import settings
from django.utils import timezone

from accounting.lms.utils.xero.base import xero_execute_booking
from transaction.models import Transaction

Actual behaviour

When I sort using the vscode command Python Refactor: Sort Imports the I get:

from datetime import date, datetime
from typing import List

import pytz
from accounting.lms.utils.xero.base import xero_execute_booking
from django.conf import settings
from django.utils import timezone
from transaction.models import Transaction

Steps to reproduce:

Just try to sort imports as I explained above and it should happen.

Logs

Here are the logs from vscode

> ~/Development/virtual_env/bin/python ~/.vscode/extensions/ms-python.python-2020.9.112786/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.9.112786/pythonFiles/sortImports.py - --diff
cwd: ~/Development/backend/src/accounting/lms/utils/xero
> ~/Development/virtual_env/bin/python ~/.vscode/extensions/ms-python.python-2020.9.112786/pythonFiles/pyvsc-run-isolated.py ~/.vscode/extensions/ms-python.python-2020.9.112786/pythonFiles/sortImports.py - --diff
cwd: ~/Development/backend/src/accounting/lms/utils/xero

Metadata

Metadata

Assignees

Labels

area-formattingbugIssue identified by VS Code Team member as probable bugneeds proposalNeed to make some design decisions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions