#2455·isort

`--fss` may lead to incorrect import separation for mixed multi-line and alias imports

Author: n0gu-furiosaCreated Jan 22, 2026Updated Aug 5, 2026

When using --force-sort-within-sections (--fss), imports from the same module can be incorrectly separated.

Reproduction (repro.py):

python
from module import (
    AAAAAAAAAAAAAAAAAAAAAAAAAA,
    BBBBBBBBBBBBBBBBBBBBBBBBBB,
    CCCCCCCCCCCCCCCCCCCCCCCCCC,
)
from module import DDDDDDDDDDDDDDDDDDDDDDDDDD as d
from module import (
    EEEEEEEEEEEEEEEEEEEEEEEEEE,
    FFFFFFFFFFFFFFFFFFFFFFFFFF,
    GGGGGGGGGGGGGGGGGGGGGGGGGG,
)

Sorting this file with isort repro.py --fss results in imports from the same module being split in a seemingly meaningless way:

python
from module import (
    AAAAAAAAAAAAAAAAAAAAAAAAAA,
    BBBBBBBBBBBBBBBBBBBBBBBBBB,
    CCCCCCCCCCCCCCCCCCCCCCCCCC,
)
from module import (
    EEEEEEEEEEEEEEEEEEEEEEEEEE,
    FFFFFFFFFFFFFFFFFFFFFFFFFF,
    GGGGGGGGGGGGGGGGGGGGGGGGGG,
)
from module import DDDDDDDDDDDDDDDDDDDDDDDDDD as d

This happens because _with_from_imports sees those as three separate groups, and then during within-section sorting sorting.section_key determines that import (... should precede import D....

It's hard to say that isort is doing something wrong, but splitting imports from the same module is undesirable. My preferred output in this situation would be:

python
from module import (
    AAAAAAAAAAAAAAAAAAAAAAAAAA,
    BBBBBBBBBBBBBBBBBBBBBBBBBB,
    CCCCCCCCCCCCCCCCCCCCCCCCCC,
    EEEEEEEEEEEEEEEEEEEEEEEEEE,
    FFFFFFFFFFFFFFFFFFFFFFFFFF,
    GGGGGGGGGGGGGGGGGGGGGGGGGG,
)
from module import DDDDDDDDDDDDDDDDDDDDDDDDDD as d

I think there are a few ways to approach this:

  • Add a new configuration option: Introduce a flag (e.g., --force-separate-as-imports) that operates within the _with_from_imports function to explicitly place as_imports at the end of the list.
  • Normalize ( in section_key: Modify the key generation so that module import (AAAA is treated as module import AAAA for sorting purposes. This would not produce my "preferred output," but it would at least leave repro.py unchanged, avoiding multiple separated from module import ( blocks.
  • No new flag, no new sort logic, just merge outputs from new_section_output: Iterate over the new section output, parse them again, and merge imports where possible. I personally think this would be the least preferred option because it doesn't integrate well with the rest of the system and would have a high maintenance cost.

I would appreciate any input from the maintainers on whether this is worth addressing and, if so, which approach is preferred. I am happy to contribute a PR if the team agrees on a direction.