Skip to content

Add a rule to enforce lazy imports#23777

Merged
charliermarsh merged 1 commit intomainfrom
charlie/lazy-rule
Mar 9, 2026
Merged

Add a rule to enforce lazy imports#23777
charliermarsh merged 1 commit intomainfrom
charlie/lazy-rule

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Mar 7, 2026

Summary

TID254 enforces the use of lazy imports. You can specify a set of modules, similar to banned-module-level-imports, or "all":

# Require every module-level import to be lazy.
banned-eager-imports = "all"

# Require lazy imports for specific modules.
banned-eager-imports = [
    "boto3",
    "botocore",
]

@charliermarsh charliermarsh added rule Implementing or modifying a lint rule preview Related to preview mode features labels Mar 7, 2026
@charliermarsh
Copy link
Copy Markdown
Member Author

Not certain that this is the right category. Also bothered by this inconsistency:

[lint.flake8-tidy-imports]
ban-relative-imports = "all"
banned-eager-imports = "all"
banned-module-level-imports = [
    "boto3",
    "botocore",
]

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 7, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh charliermarsh marked this pull request as ready for review March 7, 2026 03:27
@astral-sh-bot astral-sh-bot bot requested a review from ntBre March 7, 2026 03:27
@charliermarsh charliermarsh enabled auto-merge (squash) March 9, 2026 17:52
@charliermarsh charliermarsh merged commit 2e227cd into main Mar 9, 2026
42 checks passed
@charliermarsh charliermarsh deleted the charlie/lazy-rule branch March 9, 2026 17:57
@Tishka17
Copy link
Copy Markdown

Tishka17 commented Mar 9, 2026

What about a rule to forbid lazy imports?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

preview Related to preview mode features rule Implementing or modifying a lint rule

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants