Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Add a rule to flag lazy imports that are eagerly evaluated#25016

Merged
charliermarsh merged 4 commits into
mainfrom
charlie/lazy-immediate
May 6, 2026
Merged

Add a rule to flag lazy imports that are eagerly evaluated#25016
charliermarsh merged 4 commits into
mainfrom
charlie/lazy-immediate

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

Summary

This PR adds a new rule (TID255) to flag PEP 810 lazy imports that are resolved immediately during module import execution.

For example:

lazy import foo

class Bar(foo.Foo): ...

Here, foo is evaluated while the module is being loaded, so the import is not meaningfully lazy.

We're also offering an unsafe fix to remove lazy when the import statement imports a single member.

Closes #25014.

@charliermarsh charliermarsh requested a review from ntBre May 6, 2026 17:29
@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label May 6, 2026
@charliermarsh charliermarsh force-pushed the charlie/lazy-immediate branch from 1aa6a51 to bcd0a05 Compare May 6, 2026 17:31
@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot Bot commented May 6, 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 force-pushed the charlie/lazy-immediate branch from 6a6e68e to cbcfe6c Compare May 6, 2026 17:57
@charliermarsh charliermarsh marked this pull request as ready for review May 6, 2026 17:57
@charliermarsh charliermarsh added the preview Related to preview mode features label May 6, 2026
…port_immediately_resolved.rs

Co-authored-by: Brent Westbrook <[email protected]>
@charliermarsh charliermarsh enabled auto-merge (squash) May 6, 2026 20:47
@charliermarsh charliermarsh merged commit 41f8a52 into main May 6, 2026
43 checks passed
@charliermarsh charliermarsh deleted the charlie/lazy-immediate branch May 6, 2026 20:48
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
…#25016)

## Summary

This PR adds a new rule (`TID255`) to flag PEP 810 lazy imports that are
resolved immediately during module import execution.

For example:

```python
lazy import foo

class Bar(foo.Foo): ...
```

Here, `foo` is evaluated while the module is being loaded, so the import
is not meaningfully lazy.

We're also offering an unsafe fix to remove `lazy` when the import
statement imports a single member.

Closes astral-sh#25014.

---------

Co-authored-by: Brent Westbrook <[email protected]>
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.

Lint against PEP 810 lazy imports that would be immediately resolved

2 participants