← Latest briefing

Technology

Developer releases flake8-lazy tool to help Python packages adopt lazy imports in version 3.15

The utility helps codebases configure lazy imports introduced in PEP 810, aiming to reduce CLI startup times and unnecessary module loading.

The short version

  • Python 3.15a7 introduces support for lazy imports under PEP 810, deferring module loading until an object is actually accessed.
  • A new linting and automation tool, flake8-lazy, was created to identify unneeded top-level imports and generate backward-compatible configuration.
  • Initial benchmarks on several developer command-line tools show speedups between 10% and 3x on help commands.
  • A known issue in Python 3.15a7 where the import disabling flag behaves incorrectly is currently pending a fix.

Key facts

  • PEP 810 introduces lazy imports to Python 3.15a7, allowing packages to avoid loading modules that are not accessed during execution.[Hacker News]
  • The developer introduced flake8-lazy, a tool that checks for missing lazy declarations, validates __lazy_modules__ syntax, and can automatically apply import configurations.[Hacker News]
  • Lazy imports can be configured either via the Python 3.15 native 'lazy import' syntax or through the backward-compatible '__lazy_modules__' list format.[Hacker News]
  • Benchmarking help commands across multiple tools showed execution time improvements, including a 2x speedup for flake8-lazy and roughly 3x speedups for repo-review and cibuildwheel.[Hacker News]

What remains uncertain

  • The behavior of the `-X lazy_imports=none` flag in Python 3.15a7 contains a known bug that prevents proper disabling of __lazy_modules__, which currently blocks its adoption in the standard library.[Hacker News]

Sources