Highlight PEP 810 soft keyword `lazy` only with `lazy import` / `lazy from` · Issue #276 · MagicStack/MagicPython
Repository navigation
Highlight PEP 810 soft keyword lazy only with lazy import / lazy from #276
New issue
New issue
Open
Open
Highlight PEP 810 soft keyword
lazy only with lazy import / lazy from #276
Description
@jiangyangcreate's profile jiangyangcreate opened on Oct 21, 2026Summary
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 |