ruff
e46e458e - Allow users to ban lazy imports (#23847)

Commit
83 days ago
Allow users to ban lazy imports (#23847) ## Summary This PR renames TID254 to `lazy-import-mismatch` and expands it into a single rule with two complementary settings: `require-lazy` and `ban-lazy`. Both settings accept `"all"`, `list[str]`, or `{ include = ..., exclude = [...] }`, and we validate that the two selectors don’t overlap. This covers the two main use-cases users asked for: - Require lazy imports by default, except for known side-effectful modules. Example: ```toml require-lazy = { include = "all", exclude = ["sitecustomize"] } ``` This enforces lazy imports everywhere Ruff can rewrite them, while leaving sitecustomize eager. - Forbid lazy imports for modules that must stay eager, or even forbid lazy imports by default with a small allowlist. ```toml # Require `sitecustomize` to stay eager. ban-lazy = ["sitecustomize"] # Ban lazy imports everywhere except `typing`. ban-lazy = { include = "all", exclude = ["typing"] } ```
Author
Parents
Loading