Skip to content

Support lazy imports #5042

@hugovk

Description

@hugovk

Is your feature request related to a problem? Please describe.

Python 3.15 adds support for the lazy soft keyword:

This has now available for testing in Python 3.15.0a7:

Describe the solution you'd like

Add support for the lazy soft keyword.

Describe alternatives you've considered

Wait for the next Ruff release? astral-sh/ruff#21305

Additional context

lazy import random

if __name__ == "__main__":
    print(random.randint(1, 6))
black --version
black, 26.3.0 (compiled: yes)
Python (CPython) 3.14.3black 1.py
error: cannot format 1.py: Cannot parse: 1:5: lazy import random

Oh no! 💥 💔 💥
1 file failed to reformat.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions