-
Notifications
You must be signed in to change notification settings - Fork 231
Open
Labels
Description
ruff rule TID253
# banned-module-level-imports (TID253)
Derived from the **flake8-tidy-imports** linter.
## What it does
Checks for module-level imports that should instead be imported lazily
(e.g., within a function definition, or an `if TYPE_CHECKING:` block, or
some other nested context).
## Why is this bad?
Some modules are expensive to import. For example, importing `torch` or
`tensorflow` can introduce a noticeable delay in the startup time of a
Python program.
In such cases, you may want to enforce that the module is imported lazily
as needed, rather than at the top of the file. This could involve inlining
the import into the function that uses it, rather than importing it
unconditionally, to ensure that the module is only imported when necessary.
## Options
- `lint.flake8-tidy-imports.banned-module-level-imports`
We currently enforce this in AiiDA for some modules using a custom test/verdi command, but enabling this rule would make this more robust.