isort icon indicating copy to clipboard operation
isort copied to clipboard

isort dont respect pylint ungrouped-imports checks

Open akayunov opened this issue 7 years ago • 2 comments

Hi, isort sort all import by alphabet but pylint want to group import from same module, example: isort variant:

import functools
import os
from copy import deepcopy
from functools import reduce, wraps
from itertools import repeat

pylint variant

import os
from copy import deepcopy

import functools
from functools import reduce, wraps

from itertools import repeat

As you can see import from functools in pylint variat are grouped.

akayunov avatar Jul 05 '19 09:07 akayunov

By default isort moves import xxx lines to the top of the sections, before from xxx import yyy lines. This can be changed by adding force_sort_within_sections=True to .isort.cfg. However, when I enabled it, I notice another problem - isort starts moving # pylist disable=xxx comments to the top of the sections instead of leaving them where they are, even when none of the imports were actually reordered:

import os
# pylint: disable=app-dependency
import sys
# pylint: enable=app-dependency

becomes

# pylint: disable=app-dependency
import os
import sys

# pylint: enable=app-dependency

If I remove the force_sort_within_sections=True option, the result is correct:

import os
# pylint: disable=app-dependency
import sys

# pylint: enable=app-dependency

peterlevi avatar Jul 16 '19 12:07 peterlevi

This is fixed in the latest version of isort. Thanks for reporting!

timothycrosley avatar Jul 16 '20 05:07 timothycrosley