1717
1818import astroid
1919import astroid .modutils
20+ import isort
2021from astroid import nodes
2122from astroid .nodes ._base_nodes import ImportNode
2223
3536from pylint .interfaces import HIGH
3637from pylint .reporters .ureports .nodes import Paragraph , Section , VerbatimText
3738from pylint .typing import MessageDefinitionTuple
38- from pylint .utils import IsortDriver
3939from pylint .utils .linterstats import LinterStats
4040
4141if TYPE_CHECKING :
@@ -322,6 +322,7 @@ def _make_graph(
322322DEFAULT_PREFERRED_MODULES = ()
323323
324324
325+ # pylint: disable-next = too-many-instance-attributes
325326class ImportsChecker (DeprecatedMixin , BaseChecker ):
326327 """BaseChecker for import statements.
327328
@@ -458,6 +459,15 @@ def __init__(self, linter: PyLinter) -> None:
458459 )
459460 self ._excluded_edges : defaultdict [str , set [str ]] = defaultdict (set )
460461
462+ self ._isort_config = isort .Config (
463+ # There is no typo here. EXTRA_standard_library is
464+ # what most users want. The option has been named
465+ # KNOWN_standard_library for ages in pylint, and we
466+ # don't want to break compatibility.
467+ extra_standard_library = linter .config .known_standard_library ,
468+ known_third_party = linter .config .known_third_party ,
469+ )
470+
461471 def open (self ) -> None :
462472 """Called before visiting project (i.e set of modules)."""
463473 self .linter .stats .dependencies = {}
@@ -746,7 +756,6 @@ def _is_fallback_import(
746756 imports = [import_node for (import_node , _ ) in imports ]
747757 return any (astroid .are_exclusive (import_node , node ) for import_node in imports )
748758
749- # pylint: disable = too-many-statements
750759 def _check_imports_order (self , _module_node : nodes .Module ) -> tuple [
751760 list [tuple [ImportNode , str ]],
752761 list [tuple [ImportNode , str ]],
@@ -765,7 +774,6 @@ def _check_imports_order(self, _module_node: nodes.Module) -> tuple[
765774 third_party_not_ignored : list [tuple [ImportNode , str ]] = []
766775 first_party_not_ignored : list [tuple [ImportNode , str ]] = []
767776 local_not_ignored : list [tuple [ImportNode , str ]] = []
768- isort_driver = IsortDriver (self .linter .config )
769777 for node , modname in self ._imports_stack :
770778 if modname .startswith ("." ):
771779 package = "." + modname .split ("." )[1 ]
@@ -775,7 +783,7 @@ def _check_imports_order(self, _module_node: nodes.Module) -> tuple[
775783 ignore_for_import_order = not self .linter .is_message_enabled (
776784 "wrong-import-order" , node .fromlineno
777785 )
778- import_category = isort_driver .place_module (package )
786+ import_category = isort .place_module (package , config = self . _isort_config )
779787 node_and_package_import = (node , package )
780788
781789 match import_category :
0 commit comments