Skip to content

Add lazy as a recognised keyword in import statements for syntax highlighting #148465

@benediktjohannes

Description

@benediktjohannes

Feature or enhancement

Proposal:

Goal

Allow lazy to be coloured by IDEs and syntax highlighters exactly like import and from when it appears in an import statement.

Example

lazy import math
lazy import numpy as np

(and lazy should be red as well)

Why

lazy is already used as a special marker in some lazy‑import implementations (e.g., custom import hacks, or PyPy's lazy loading).

Making it a proper keyword token in the grammar (or at least a pseudo‑keyword inside import context) would let editors colour it consistently, improving readability.

Implementation idea

Extend the lexer to treat lazy as a keyword only when it follows import or from ... import. This avoids breaking existing code that uses lazy as a variable name elsewhere.

Benefit for developers

Immediate visual cue that an import is deferred / lazy.

No need for special comments or pragmas to trigger highlighting.

Has this already been discussed elsewhere?

This is a minor feature, which does not need previous discussion elsewhere

Links to previous discussion of this feature:

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    pendingThe issue will be closed if no feedback is provided

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions