unsorted-imports (I001)
Added in v0.0.110 · Category: style · Related issues · View source
Derived from the isort linter.
Fix is sometimes available.
What it does
De-duplicates, groups, and sorts imports based on the provided isort settings.
By default, imports are categorized into the following sections in order:
future(__future__)standard-library(e.g.,sys,os,json)third-party(e.g.,numpy,pandas)first-party(modules within the current project or package)local-folder(relative imports starting with., e.g.,from . import utils)
With the default settings, each section is separated by a blank line. Within a section, Ruff
generally places import statements before from imports and sorts each group by module name.
Ruff defaults to two blank lines between a top-level import block and a function or class
definition, and one blank line before other top-level statements. In stub files (.pyi), the
default is one blank line in either case.
See the FAQ for more information on how Ruff determines which imports are first-party and for how Ruff compares to isort more broadly.
Why is this bad?
Consistency is good. Use a common convention for imports to make your code more readable and idiomatic.
Example
Use instead:
Options
See the isort settings for all available
configuration options.