PyCQA/isort

Support explicit lazy imports in Python 3.15 (PEP 810)

Aperta

#2462 aperta il 25 feb 2026

 (4 commenti) (3 reazioni) (0 assegnatari)Python (594 fork)batch import
enhancementhelp wanted

Metriche repository

Star
 (6146 stelle)
Metriche merge PR
 (Merge medio 2g 23h) (7 PR mergiate in 30 g)

Descrizione

PEP 810 "Explicit lazy imports" has been accepted and is coming to Python 3.15 (2026-03-10's 3.15.0a7 will be the first release).

This adds a new lazy keyword for imports:

lazy import json
lazy from json import dumps

And also a __lazy_modules__ for backwards compatibility with pre-3.15:

__lazy_modules__ = ["json"]
import json

It would be useful to also sort __lazy_modules__. Two options:

  • Alphabetical
  • Follow the isort settings, for example: stdlib, third-party, local

The Steering Council's acceptance said:

We agree that the PEP should take no position on any style recommendations for sorting lazy imports. While we generally like the idea of grouping lazy imports together, let’s leave that up to the linters and auto-formatters to decide the details.

See also https://github.com/astral-sh/ruff/issues/21305.

Guida contributor