Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 12 additions & 1 deletion doc/python-syntax-enhanced.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.)
Expand Down Expand Up @@ -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
Expand Down
5 changes: 0 additions & 5 deletions syntax/python.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions tests/test_loading.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading