From 99964e2ea704465f25207c519fefb2bb6d6931bb Mon Sep 17 00:00:00 2001 From: Jon Parise Date: Sun, 24 Aug 2025 12:31:08 +0200 Subject: [PATCH] runtime(python): support 'type's soft keyword form `type` became a soft keyword in Python 3.12. In that form, it is a statement that declares a type alias: # type_stmt ::= 'type' identifier [type_params] "=" expression type Point = tuple[float, float] To implement support for this, this change does three things: 1. adds a `pythonType` group (linked to `Type`) 2. matches `type` followed by an identifier as `pythonStatement` 3. continues to match `type` in other forms as `pythonBuiltin` Ref: - https://docs.python.org/3/reference/lexical_analysis.html#soft-keywords - https://docs.python.org/3/reference/simple_stmts.html#the-type-statement closes: #18090 Signed-off-by: Jon Parise Signed-off-by: Zvezdan Petkovic Signed-off-by: Christian Brabandt --- runtime/syntax/python.vim | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/runtime/syntax/python.vim b/runtime/syntax/python.vim index 320fd785c7..e963155d4a 100644 --- a/runtime/syntax/python.vim +++ b/runtime/syntax/python.vim @@ -1,10 +1,11 @@ " Vim syntax file " Language: Python " Maintainer: Zvezdan Petkovic -" Last Change: 2025 Aug 18 +" Last Change: 2025 Aug 23 " Credits: Neil Schemenauer " Dmitry Vasiliev " Rob B +" Jon Parise " " This version is a major rewrite by Zvezdan Petkovic. " @@ -112,6 +113,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 pythonStatement "\>>\|\.\.\.\)\s\+\)\=\zs\%(\h\|\%(\h\|[[(]\).\{-}\%(\w\|[])]\)\)\s*\n\%(\s*\.\.\.\s\)\=\s\+@\%(.\{-}\n\%(\s*\.\.\.\s\)\=\s\+@\)*" - \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonClass,pythonFunction,pythonDoctestValue + \ contains=ALLBUT,pythonDecoratorName,pythonDecorator,pythonClass,pythonFunction,pythonType,pythonDoctestValue \ transparent syn match pythonClass "\h\w*" display contained syn match pythonFunction "\h\w*" display contained +syn match pythonType "\h\w*" display contained syn match pythonComment "#.*$" contains=pythonTodo,@Spell syn keyword pythonTodo FIXME NOTE NOTES TODO XXX contained @@ -300,10 +303,12 @@ if !exists("python_no_builtin_highlight") syn keyword pythonBuiltin memoryview min next object oct open ord pow syn keyword pythonBuiltin print property range repr reversed round set syn keyword pythonBuiltin setattr slice sorted staticmethod str sum super - syn keyword pythonBuiltin tuple type vars zip __import__ + syn keyword pythonBuiltin tuple vars zip __import__ + " only match `type` as a builtin when it's not followed by an identifier + syn match pythonBuiltin "\>>\s\|\.\.\.\s\|"""\|'''\)\@!\S\++ end="$" \ contained @@ -387,6 +392,7 @@ hi def link pythonDecorator Define hi def link pythonDecoratorName Function hi def link pythonClass Structure hi def link pythonFunction Function +hi def link pythonType Type hi def link pythonComment Comment hi def link pythonTodo Todo hi def link pythonString String