Add support for lazy import parsing#23755
Merged
charliermarsh merged 1 commit intomainfrom Mar 6, 2026
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 87.07%. The percentage of expected errors that received a diagnostic held steady at 77.62%. |
Memory usage reportMemory usage unchanged ✅ |
|
ca3e429 to
487b7c5
Compare
|
487b7c5 to
2bf7354
Compare
dhruvmanila
approved these changes
Mar 6, 2026
Member
dhruvmanila
left a comment
There was a problem hiding this comment.
Looks great, thanks!
I've also omitted support for flagging semantic syntax errors (e.g.,
lazy importinsidedef).
👍
MichaReiser
approved these changes
Mar 6, 2026
Collaborator
|
Probably fine for now, but this causes ❯ echo "lazy import os" | cargo run -p ruff -- check --no-cache --isolated --select I --output-format concise --fix -
import os
Found 1 error (1 fixed, 0 remaining). |
Member
Author
|
Oh nice thank you, I will fix that. |
charliermarsh
added a commit
that referenced
this pull request
Mar 6, 2026
## Summary We now reject cases like: - `lazy import ...` inside functions, including `async def` - `lazy from ... import ...` inside functions, including `async def` - `lazy import ...` and `lazy from ... import ...` inside class bodies - `lazy import ...` and `lazy from ... import ...` anywhere inside a `try` statement, including `except` / `except*` - `lazy from ... import *` anywhere - `lazy from __future__ import ...` anywhere A follow-up to #23755. See: #21305.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds
is_lazyto the AST and parser, and supportslazyimport formatting in the formatter. The nameis_lazymatches the CPython AST, though we could modify it if there's demand.There are no further changes to Ruff rules or even to Ruff import sorting, since those deserve separate design discussions.
I've also omitted support for flagging semantic syntax errors (e.g.,
lazy importinsidedef).See: #21305.