Skip to content

Sorting of imports (isort) is different if the file has unsaved modifications #4891

@PeterJCLaw

Description

@PeterJCLaw

Environment data

  • VS Code version: 1.32.3 (have also seen this on older versions)
  • Extension version: 2019.2.5558 (have also seen this on older versions)
  • OS and version: Ubuntu 16.04.6
  • Python version: 3.5.2 (have also seen this on other versions)
  • Type of virtual environment used: venv
  • Relevant/affected Python packages and their versions: I currently have isort 4.3.15, though I've seen this on older versions

Expected behaviour

That when running the "Sort Imports" command on a file, the imports are sorted according to my setup.cfg config regardless of whether the file is currently saved or not.

Actual behaviour

When running the "Sort Imports" command on a file:

  • If the file is saved, my setup.cfg config is respected
  • If the file has modifications, my setup.cfg config is not respected

Steps to reproduce:

Given this config:

# setup.cfg
[isort]
length_sort = True
# demo.py
import os
import logging
import collections
  1. put setup.cfg and demo.py next to each other in a new folder
  2. open that folder as a workspace in VSCode
  3. open demo.py
  4. "Sort imports" within demo.py, it should be unchanged
  5. edit demo.py, without saving it
  6. "Sort imports" within demo.py, note that its imports have changed ordering to ignore the length_sort option

This reproduces with much more complex configs, and other options are also ignored, so I strongly suspect the setup.cfg file isn't being picked up as a whole if the file is modified.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-intellisenseLSP-related functionality: auto-complete, docstrings, navigation, refactoring, etc.bugIssue identified by VS Code Team member as probable bug

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions