-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
Description
This issue tracks support for lazy imports in Ruff.
Python 3.15 introduced PEP 810 - Explicit lazy imports. We have done the following:
- Update the parser
- Update the formatter
- Update the semantic model (though according to this subheading these will be treated the same as ordinary imports for our purposes)
But we may also want to consider some lints. For example:
- ✅ Sorting these imports - Retain
lazykeyword when sorting imports #23762 - Adjust the fixes in
flake8-type-checkingto suggest that typing-only imports be lazily imported rather than gated behindif TYPE_CHECKING, as per this use-case in the PEP. - Relatedly - replacing existing
if TYPE_CHECKING: ...imports with lazy imports. - Suggesting lazy imports any time we see an import not at the beginning of the file. (Developers sometimes approximate lazy imports these days by importing in the body of a function, for example.)
- ✅ Enforce lazy imports always (or for configurable set of modules) - Add a rule to enforce lazy imports #23777
- Conversely, removing
lazyif we can guarantee that the import will be evaluated (e.g. by a top-level statement in the module).
Reactions are currently unavailable