Skip to content

Highlight PEP 810 soft keyword lazy only with lazy import / lazy from #276

Open

Description

@jiangyangcreate

Summary

Python 3.15 adds deferred / lazy imports (What’s New in Python 3.15 – Lazy imports, PEP 810).

lazy is a soft keyword only in these forms:

lazy import foo
lazy from foo import bar

In all other positions it remains a normal identifier (e.g. lazy = 1, def lazy(): ..., from lazy import x).

VS Code / VSCodium themes such as Dark Modern already color keyword.control.import.* (purple). The bundled MagicPython grammar (extensions/python/syntaxes/MagicPython.tmLanguage.json) does not yet scope lazy in those positions, so soft-keyword uses stay unhighlighted while import / from are highlighted.

Requested change

Do not add lazy to the general keyword list.

Optionally capture lazy only when it immediately precedes import or from, with a scope such as keyword.control.import.lazy.python (same approach as Sublime Text’s Python.sublime-syntax import-statements).

Example (MagicPython #import / source YAML shape):

- begin: \b(?<!\.)(?:(lazy)\s+)?(from)\b(?=.+import)
  beginCaptures:
    '1': {name: keyword.control.import.lazy.python}
    '2': {name: keyword.control.import.python}

- begin: \b(?<!\.)(?:(lazy)\s+)?(import)\b
  beginCaptures:
    '1': {name: keyword.control.import.lazy.python}
    '2': {name: keyword.control.import.python}

Test cases

Code lazy should be keyword?
lazy import os yes
lazy from os import path yes
lazy = 1 no
x.lazy no
def lazy(): pass no
from lazy import x no

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions