Skip to content

Retain lazy keyword when sorting imports#23762

Merged
charliermarsh merged 1 commit intomainfrom
charlie/lazy-iii
Mar 8, 2026
Merged

Retain lazy keyword when sorting imports#23762
charliermarsh merged 1 commit intomainfrom
charlie/lazy-iii

Conversation

@charliermarsh
Copy link
Copy Markdown
Member

@charliermarsh charliermarsh commented Mar 6, 2026

Summary

For now, we keep our sections as-is, but within each section, we show all the eager imports followed by all the lazy imports, e.g.:

import json
import os
import subprocess
from collections import defaultdict
from pathlib import Path
from typing import Final
lazy import ast
lazy import shutil
lazy from dataclasses import dataclass

We may change this behavior later; it shouldn't be considered stable.

See: #21305.

@charliermarsh charliermarsh added the isort Related to import sorting label Mar 6, 2026
@charliermarsh charliermarsh marked this pull request as ready for review March 6, 2026 15:53
@astral-sh-bot astral-sh-bot bot requested a review from amyreese March 6, 2026 15:53
@charliermarsh charliermarsh added the preview Related to preview mode features label Mar 6, 2026
@charliermarsh
Copy link
Copy Markdown
Member Author

Should we emit a warning if we see a lazy import when sorting without preview enabled?

@astral-sh-bot
Copy link
Copy Markdown

astral-sh-bot bot commented Mar 6, 2026

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dylwil3
Copy link
Copy Markdown
Collaborator

dylwil3 commented Mar 6, 2026

Should we emit a warning if we see a lazy import when sorting without preview enabled?

I think this will sort of happen by default because either:

  1. The user doesn't have target-version set to 3.15, so they'll get a syntax error
  2. They do have it set to 3.15, in which case they'll get this warning:
warning: Support for Python 3.15 is under development and may be unstable. Enable `preview` to remove this warning.

@amyreese amyreese requested a review from MichaReiser March 6, 2026 20:32
@charliermarsh charliermarsh merged commit 4e7c8db into main Mar 8, 2026
45 checks passed
@charliermarsh charliermarsh deleted the charlie/lazy-iii branch March 8, 2026 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

isort Related to import sorting preview Related to preview mode features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants