Repository: pylint-dev/pylint

Issue:
# Fix setting options for import order checker

## Type of Changes

|     | Type                   |
| --- | ---------------------- |
| ✓   | :bug: Bug fix          |

## Description

Fix regression in 6ce60320a:
In `__init__` the options are not parsed yet and hence will always be the defaults.


Closes #10801


I was looking for a way to avoid this in general. However that requires a bit more refactoring to either:
- Don't set `PyLinter.options` on `__init__.py` to detect access to it before being set (from config)
- (Preferred): Don't init plugins until options are parsed. Registering would register the classes instead of the instances

Implementation patch:
diff --git a/pylint/checkers/imports.py b/pylint/checkers/imports.py
index b069a7a0c6..b045f74c21 100644
--- a/pylint/checkers/imports.py
+++ b/pylint/checkers/imports.py
@@ -322,7 +322,6 @@ def _make_graph(
 DEFAULT_PREFERRED_MODULES = ()
 
 
-# pylint: disable-next = too-many-instance-attributes
 class ImportsChecker(DeprecatedMixin, BaseChecker):
     """BaseChecker for import statements.
 
@@ -459,15 +458,6 @@ def __init__(self, linter: PyLinter) -> None:
         )
         self._excluded_edges: defaultdict[str, set[str]] = defaultdict(set)
 
-        self._isort_config = isort.Config(
-            # There is no typo here. EXTRA_standard_library is
-            # what most users want. The option has been named
-            # KNOWN_standard_library for ages in pylint, and we
-            # don't want to break compatibility.
-            extra_standard_library=linter.config.known_standard_library,
-            known_third_party=linter.config.known_third_party,
-        )
-
     def open(self) -> None:
         """Called before visiting project (i.e set of modules)."""
         self.linter.stats.dependencies = {}
@@ -756,6 +746,21 @@ def _is_fallback_import(
         imports = [import_node for (import_node, _) in imports]
         return any(astroid.are_exclusive(import_node, node) for import_node in imports)
 
+    @property
+    def _isort_config(self) -> isort.Config:
+        """Get the config for use with isort.
+
+        Only valid after CLI parsing finished, i.e. not in __init__
+        """
+        return isort.Config(
+            # There is no typo here. EXTRA_standard_library is
+            # what most users want. The option has been named
+            # KNOWN_standard_library for ages in pylint, and we
+            # don't want to break compatibility.
+            extra_standard_library=self.linter.config.known_standard_library,
+            known_third_party=self.linter.config.known_third_party,
+        )
+
     def _check_imports_order(self, _module_node: nodes.Module) -> tuple[
         list[tuple[ImportNode, str]],
         list[tuple[ImportNode, str]],
@@ -763,7 +768,7 @@ def _check_imports_order(self, _module_node: nodes.Module) -> tuple[
     ]:
         """Checks imports of module `node` are grouped by category.
 
-        Imports must follow this order: standard, 3rd party, local
+        Imports must follow this order: standard, 3rd party, 1st party, local
         """
         std_imports: list[tuple[ImportNode, str]] = []
         third_party_imports: list[tuple[ImportNode, str]] = []
diff --git a/pylint/checkers/utils.py b/pylint/checkers/utils.py
index 9e8a3906e9..7536658209 100644
--- a/pylint/checkers/utils.py
+++ b/pylint/checkers/utils.py
@@ -6,7 +6,7 @@
 
 from __future__ import annotations
 
-import _string  # pylint: disable=wrong-import-order # Ruff and Isort disagree about the order here
+import _string
 import builtins
 import fnmatch
 import itertools


Test patch:
diff --git a/tests/functional/w/wrong_import_order2.py b/tests/functional/w/wrong_import_order2.py
index 7157512ddc..6f68906738 100644
--- a/tests/functional/w/wrong_import_order2.py
+++ b/tests/functional/w/wrong_import_order2.py
@@ -8,6 +8,7 @@
 
 # external imports
 import isort
+import datetime  # std import that should be treated as third-party
 
 from six import moves