]> git.ipfire.org Git - thirdparty/vim.git/commitdiff
runtime(python): highlight the 'lazy' soft keyword
authorJon Parise <jon@indelible.org>
Sun, 26 Jul 2026 15:20:02 +0000 (15:20 +0000)
committerChristian Brabandt <cb@256bit.org>
Sun, 26 Jul 2026 15:20:02 +0000 (15:20 +0000)
Lazy imports (PEP 810, to be released in Python 3.15) introduces a
`lazy` soft keyword that's recognized when it precedes a `from` or
`import` keyword.

closes: #20342

Signed-off-by: Jon Parise <jon@indelible.org>
Signed-off-by: Christian Brabandt <cb@256bit.org>
runtime/syntax/python.vim
runtime/syntax/testdir/dumps/python_import_00.dump [new file with mode: 0644]
runtime/syntax/testdir/input/python_import.py [new file with mode: 0644]

index e483468995eaec93ef115cb158402fff6cb651ed..c66fee665275255c614d147553a6d49bd75bab13 100644 (file)
@@ -6,6 +6,7 @@
 " 2025 Dec 03 by Vim Project: highlight t-strings #18679
 " 2026 Jan 26 by Vim Project: highlight constants #18922
 " 2026 Mar 11 by Vim Project: fix number performance #19630
+" 2026 May 27 by Vim Project: highlight `lazy` soft keyword (PEP 810) #20342
 " Credits:     Neil Schemenauer <nas@python.ca>
 "              Dmitry Vasiliev
 "              Rob B
@@ -120,6 +121,7 @@ syn keyword pythonAsync             async await
 " for more on this.
 syn match   pythonConditional   "^\s*\zscase\%(\s\+.*:.*$\)\@="
 syn match   pythonConditional   "^\s*\zsmatch\%(\s\+.*:\s*\%(#.*\)\=$\)\@="
+syn match   pythonInclude       "^\s*\zslazy\ze\s\+\%(from\|import\)\>"
 syn match   pythonStatement     "\<type\ze\s\+\h\w*" nextgroup=pythonType skipwhite
 
 " These names are special by convention. While they aren't real keywords,
diff --git a/runtime/syntax/testdir/dumps/python_import_00.dump b/runtime/syntax/testdir/dumps/python_import_00.dump
new file mode 100644 (file)
index 0000000..9008348
--- /dev/null
@@ -0,0 +1,20 @@
+>#+0#0000e05#ffffff0| |I|m|p|o|r|t|s| +0#0000000&@65
+|i+0#e000e06&|m|p|o|r|t| +0#0000000&|j|s|o|n| @63
+|i+0#e000e06&|m|p|o|r|t| +0#0000000&|o|s|.|p|a|t|h| |a+0#af5f00255&|s| +0#0000000&|p| @55
+|f+0#e000e06&|r|o|m| +0#0000000&|j|s|o|n| |i+0#e000e06&|m|p|o|r|t| +0#0000000&|d|u|m|p|s|,| |l|o|a|d|s| @45
+|f+0#e000e06&|r|o|m| +0#0000000&|j|s|o|n| |i+0#e000e06&|m|p|o|r|t| +0#0000000&|d|u|m|p|s| |a+0#af5f00255&|s| +0#0000000&|d| @47
+|f+0#e000e06&|r|o|m| +0#0000000&|o|s| |i+0#e000e06&|m|p|o|r|t| +0#0000000&|*| @58
+|f+0#e000e06&|r|o|m| +0#0000000&|.| |i+0#e000e06&|m|p|o|r|t| +0#0000000&|s|u|b|m|o|d|u|l|e| @51
+|f+0#e000e06&|r|o|m| +0#0000000&|.+0#00e0e07&@2|p+0#0000000&|k|g|.|s|u|b| |i+0#e000e06&|m|p|o|r|t| +0#0000000&|t|h|i|n|g| @46
+@75
+|#+0#0000e05&| |L|a|z|y| |i|m|p|o|r|t|s| |(|P|E|P| |8|1|0|)| +0#0000000&@50
+|l+0#e000e06&|a|z|y| +0#0000000&|i+0#e000e06&|m|p|o|r|t| +0#0000000&|j|s|o|n| @58
+|l+0#e000e06&|a|z|y| +0#0000000&|f+0#e000e06&|r|o|m| +0#0000000&|j|s|o|n| |i+0#e000e06&|m|p|o|r|t| +0#0000000&|d|u|m|p|s| @47
+|l+0#e000e06&|a|z|y| +0#0000000&|f+0#e000e06&|r|o|m| +0#0000000&|.| |i+0#e000e06&|m|p|o|r|t| +0#0000000&|s|u|b|m|o|d|u|l|e| @46
+|l+0#e000e06&|a|z|y| +0#0000000&|f+0#e000e06&|r|o|m| +0#0000000&|c|o|l@1|e|c|t|i|o|n|s| |i+0#e000e06&|m|p|o|r|t| +0#0000000&|O|r|d|e|r|e|d|D|i|c|t| |a+0#af5f00255&|s| +0#0000000&|O|D| @28
+@75
+|#+0#0000e05&| |`|l|a|z|y|`| |i|s| |a| |s|o|f|t| |k|e|y|w|o|r|d| |t|h|a|t|'|s| |o|n|l|y| |r|e|c|o|g|n|i|z|e|d| |i|n| |i|m|p|o|r|t|s| +0#0000000&@14
+|l|a|z|y| |=| |1+0#e000002&| +0#0000000&@66
+|d+0#af5f00255&|e|f| +0#0000000&|l+0#00e0e07&|a|z|y|(+0#0000000&|)|:| |p+0#af5f00255&|a|s@1| +0#0000000&@58
+|~+0#4040ff13&| @73
+| +0#0000000&@56|1|,|1| @10|A|l@1| 
diff --git a/runtime/syntax/testdir/input/python_import.py b/runtime/syntax/testdir/input/python_import.py
new file mode 100644 (file)
index 0000000..4cad616
--- /dev/null
@@ -0,0 +1,18 @@
+# Imports
+import json
+import os.path as p
+from json import dumps, loads
+from json import dumps as d
+from os import *
+from . import submodule
+from ...pkg.sub import thing
+
+# Lazy imports (PEP 810)
+lazy import json
+lazy from json import dumps
+lazy from . import submodule
+lazy from collections import OrderedDict as OD
+
+# `lazy` is a soft keyword that's only recognized in imports
+lazy = 1
+def lazy(): pass