python / python/mypy

Support for `lazy` imports (PEP 810, Python 3.15+)

Open
#20,978 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Python 3.15 introduces PEP 810 - Explicit lazy imports via the new lazy soft keyword:

lazy import json
lazy from pathlib import Path

Currently mypy reports these as syntax errors. Support is needed to:

  • Update the parser to recognise lazy import and lazy from ... import statements
  • Treat lazy imports the same as regular imports for type checking purposes (as noted in PEP 810 § Typing and tools)

Related:

  • astral-sh/ruff#21305 (ruff tracking issue)
  • astral-sh/ty#2968 (ty tracking issue)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by tracing the parser support for lazy import and lazy from ... import statements, then follow the type-checking path for regular imports. Use PEP 810's “Typing and tools” section as the behavioral reference. Done means both forms are accepted and treated like regular imports for type checking without syntax errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
68/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.