diff --git a/README.md b/README.md index 60c3836..7c310ed 100644 --- a/README.md +++ b/README.md @@ -136,6 +136,11 @@ x = [] # type: list[int] To change single colors, override the groups in your vimrc after your colorscheme (with the palette on, a later `:colorscheme` re-applies it): +Brackets, commas and colons inside annotations are not colored, like the rest +of Python's punctuation. To color them, link `pythonTypeBracket`, +`pythonTypeComma`, `pythonTypeColon`, `pythonParams` or `pythonDefColon`, e.g. +`hi link pythonTypeBracket Delimiter`. + ```vim " Example: Make typing types cyan instead of orange hi pythonTypingType ctermfg=44 guifg=#00d7d7 diff --git a/doc/python-syntax-enhanced.txt b/doc/python-syntax-enhanced.txt index 7a097a1..cd90e9f 100644 --- a/doc/python-syntax-enhanced.txt +++ b/doc/python-syntax-enhanced.txt @@ -173,7 +173,9 @@ Type Annotation Groups:~ pythonTypeName CapWords / aliases / TypeVars in annotations pythonTypeDotted Dotted type paths (collections.abc.Sequence) pythonTypeUnion Union operator `|` (inside type regions only) - pythonTypeBracket Generic brackets `[` `]` and type parentheses + pythonTypeBracket Brackets `[` `]` and parentheses in a type (*) + pythonTypeComma Commas in a type (*) + pythonTypeColon Colon before an annotation (*) pythonTypeComment Type comments `# type: ...` pythonTypeNone `None` inside a type expression pythonTypeEllipsis `...` inside a type expression @@ -184,6 +186,12 @@ Type Annotation Groups:~ pythonDocstring Module / function / class docstrings pythonClassVar self / cls / mcs + (*) Not highlighted by default, like the rest of Python's punctuation. + The same applies to pythonParams (parentheses of a def) and + pythonDefColon (the colon ending a def/class header). Link them to + color them: > + hi link pythonTypeBracket Delimiter +< Core Groups:~ pythonStatement Keywords (def, class, return, type, etc.) @@ -275,6 +283,9 @@ Manual syntax resync:~ - `# type: ignore` stays a comment - Not loaded under :syntax off / manual or Neovim Tree-sitter - Removed ftplugin/python.vim, which had no effect + - Brackets, commas and colons in annotations and def/class headers are + no longer linked to Delimiter/Operator, so they look like the same + punctuation elsewhere (the groups still exist to link yourself) - g:python_enhanced_highlight_all no longer overwrites the individual g:python_highlight_* variables - Tests (tests/run.sh) run in CI on Vim (Linux/macOS/Windows) and Neovim diff --git a/syntax/python.vim b/syntax/python.vim index e160007..6a77964 100644 --- a/syntax/python.vim +++ b/syntax/python.vim @@ -643,9 +643,7 @@ hi def link pythonComment Comment hi def link pythonTodo Todo hi def link pythonShebang Comment hi def link pythonEncoding Comment -hi def link pythonDefColon Delimiter hi def link pythonDefComment pythonComment -hi def link pythonParams Delimiter hi def link pythonString String hi def link pythonRawString String @@ -694,14 +692,11 @@ endif if s:type_annotations hi def link pythonReturnArrow Operator - hi def link pythonTypeColon Operator hi def link pythonTypingType Type hi def link pythonPrimitiveType Type hi def link pythonTypeName Type hi def link pythonTypeDotted Type hi def link pythonTypeUnion Operator - hi def link pythonTypeBracket Delimiter - hi def link pythonTypeComma Delimiter hi def link pythonTypeNone Constant hi def link pythonTypeEllipsis Constant hi def link pythonTypeString String diff --git a/tests/test_loading.vim b/tests/test_loading.vim index 903873b..bafe415 100644 --- a/tests/test_loading.vim +++ b/tests/test_loading.vim @@ -65,6 +65,12 @@ call s:Check(s:loads == 1, 'sourced once on FileType, got ' . s:loads) " Palette is opt-in: by default groups keep their standard links call s:Check(execute('highlight pythonBuiltin') =~# 'links to Function', \ 'palette off by default') +" Punctuation in annotations looks like punctuation elsewhere +for s:group in ['pythonTypeBracket', 'pythonTypeComma', 'pythonTypeColon', + \ 'pythonParams', 'pythonDefColon'] + call s:Check(execute('highlight ' . s:group) !~# 'links to', + \ s:group . ' not linked') +endfor " 2. $VIMRUNTIME ahead of plugin: Vim's file wins the runtime! race, so the " plugin must force-load ours -- every time, not only the first time