isort icon indicating copy to clipboard operation
isort copied to clipboard

Checks fail with float_to_top and add_imports

Open jlamypoirier opened this issue 4 years ago • 0 comments

Checks always fails when using float_to_top and add_imports together (version 5.10.1).

When running isort on my project, it is always "fixing" all files with no diff, and chacks always fail on all files:

[...] % cat .isort.cfg
[settings]
default_section = THIRDPARTY
multi_line_output=3
include_trailing_comma=True
force_grid_wrap=0
use_parentheses=True
line_length=88
float_to_top=True
add_imports =
    from __future__ import annotations,
    logging,
known_first_party =
    [lib]
[...] % isort [lib]     
Fixing [file]
Fixing [file]
[...]
[...] % isort [lib]     
Fixing [file]
Fixing [file]
[...]
[...] % isort --check [lib]
ERROR:[file] Imports are incorrectly sorted and/or formatted.
ERROR: [file]Imports are incorrectly sorted and/or formatted.
[...]

Minimal step to reproduce

>>> import isort
>>> isort.__version__
'5.10.1'
>>> kwargs={"float_to_top":True}
>>> isort.check_code(isort.code("1\n",**kwargs),**kwargs)
True
>>> kwargs={"add_imports":["import os"]}
>>> isort.check_code(isort.code("1\n",**kwargs),**kwargs)
True
>>> kwargs={"float_to_top":True, "add_imports":["import os"]}
>>> isort.check_code(isort.code("1\n",**kwargs),**kwargs)
ERROR:  Imports are incorrectly sorted and/or formatted.
False

There is a regression test here for that particular combination but it doesn't cover code check. https://github.com/PyCQA/isort/blob/7cf1bf2d0b6c5fcd96693beb80c6222a9ccd0e6a/tests/unit/test_regressions.py#L1403

jlamypoirier avatar Dec 06 '21 21:12 jlamypoirier