wrong-import-order / C0411ΒΆ
Message emitted:
%s should be placed before %s
Description:
Used when PEP8 import order is not respected (standard imports first, then third-party libraries, then local imports).
Problematic code:
import os
from . import utils
import pylint # [wrong-import-order]
import sys # [wrong-import-order]
Correct code:
import os
import sys
import pylint
from . import utils
Additional details:
Pylint uses isort to classify imports into standard library,
third-party, first-party, and local import groups.
isort detects first-party imports by looking for packages relative to
the current working directory. As a result, running pylint from different
directories can change how the same import is classified.
For example, with the following project layout:
project/
src/
my_package/
__init__.py
module.py
An import of my_package in module.py may be treated as first-party
when pylint is run from project/src, but as third-party when pylint is
run from project.
If this warning fires, or fails to fire, inconsistently between runs, set
known-first-party in your pylint configuration to make the
classification deterministic:
[tool.pylint.imports]
known-first-party = ["my_package"]
Created by the imports checker.