Browse Source

Merge 09357048aced6245f7bd41431b59d761d855d2d0 into 69760cb3accce488cc072772ca918ac2cbf384ba

Joongi Kim 6 years ago
parent
commit
7a48474fcc
3 changed files with 263 additions and 132 deletions
  1. 4
    1
      README.rst
  2. 211
    121
      syntax/python.vim
  3. 48
    10
      test.py

+ 4
- 1
README.rst View File

24
 
24
 
25
 Changes from the original ``python.vim`` are:
25
 Changes from the original ``python.vim`` are:
26
 
26
 
27
-- Added support for Python 3 syntax highlighting
27
+- Added support for Python 3.5/3.6+ syntax highlighting, including f-string
28
+  literals and type annotations.
28
 - Added ``:Python2Syntax`` and ``:Python3Syntax`` commands which allow to
29
 - Added ``:Python2Syntax`` and ``:Python3Syntax`` commands which allow to
29
   switch between Python 2 and Python 3 syntaxes respectively without
30
   switch between Python 2 and Python 3 syntaxes respectively without
30
   reloads/restarts
31
   reloads/restarts
101
   Highlight builtin objects only
102
   Highlight builtin objects only
102
 ``python_highlight_builtin_funcs``
103
 ``python_highlight_builtin_funcs``
103
   Highlight builtin functions only
104
   Highlight builtin functions only
105
+``python_highlight_type_annotations``
106
+  Highlight Python 3.5+ type annotations
104
 ``python_highlight_exceptions``
107
 ``python_highlight_exceptions``
105
   Highlight standard exceptions
108
   Highlight standard exceptions
106
 ``python_highlight_string_formatting``
109
 ``python_highlight_string_formatting``

+ 211
- 121
syntax/python.vim View File

136
     call s:EnableByDefault("g:python_highlight_builtin_objs")
136
     call s:EnableByDefault("g:python_highlight_builtin_objs")
137
     call s:EnableByDefault("g:python_highlight_builtin_funcs")
137
     call s:EnableByDefault("g:python_highlight_builtin_funcs")
138
   endif
138
   endif
139
+  call s:EnableByDefault("g:python_highlight_type_annotations")
139
   call s:EnableByDefault("g:python_highlight_exceptions")
140
   call s:EnableByDefault("g:python_highlight_exceptions")
140
   call s:EnableByDefault("g:python_highlight_string_formatting")
141
   call s:EnableByDefault("g:python_highlight_string_formatting")
141
   call s:EnableByDefault("g:python_highlight_string_format")
142
   call s:EnableByDefault("g:python_highlight_string_format")
151
 "
152
 "
152
 
153
 
153
 syn keyword pythonStatement     break continue del
154
 syn keyword pythonStatement     break continue del
154
-syn keyword pythonStatement     exec return
155
+if s:Python2Syntax()
156
+  syn keyword pythonStatement     exec
157
+endif
158
+syn keyword pythonStatement     return
155
 syn keyword pythonStatement     pass raise
159
 syn keyword pythonStatement     pass raise
156
 syn keyword pythonStatement     global assert
160
 syn keyword pythonStatement     global assert
157
-syn keyword pythonStatement     lambda
158
 syn keyword pythonStatement     with
161
 syn keyword pythonStatement     with
159
 syn keyword pythonStatement     def class nextgroup=pythonFunction skipwhite
162
 syn keyword pythonStatement     def class nextgroup=pythonFunction skipwhite
160
 syn keyword pythonRepeat        for while
163
 syn keyword pythonRepeat        for while
163
 " we provide a dummy group here to avoid crashing pyrex.vim.
166
 " we provide a dummy group here to avoid crashing pyrex.vim.
164
 syn keyword pythonInclude       import
167
 syn keyword pythonInclude       import
165
 syn keyword pythonImport        import
168
 syn keyword pythonImport        import
169
+syn match   pythonIdentifier    "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" nextgroup=pythonFuncArgs,pythonTypeAnno display
166
 syn keyword pythonException     try except finally
170
 syn keyword pythonException     try except finally
167
 syn keyword pythonOperator      and in is not or
171
 syn keyword pythonOperator      and in is not or
172
+syn match pythonLambdaExpr   "\<lambda[^:]*:"he=s+6 contains=@pythonExpression nextgroup=@pythonExpression
173
+
174
+syn region pythonDictSetExpr matchgroup=pythonDictSetExpr start='{' end='}' contains=@pythonExpression
175
+syn region pythonListSliceExpr matchgroup=pythonListSliceExpr start='\[' end='\]' contains=@pythonExpression
176
+syn region pythonFuncArgs    matchgroup=pythonFuncArgs    start='(' end=')' contained contains=@pythonTypeExpression,@pythonExpression
177
+
178
+if !s:Python2Syntax()
179
+  if s:Enabled("g:python_highlight_type_annotations")
180
+    syn match pythonTypeAnno @:\s*['"]\?\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*['"]\?@hs=s+1 display contained contains=pythonType,pythonString nextgroup=pythonTypeUnion,pythonTypeArgs
181
+    syn match pythonTypeUnion @\s*|\s*['"]\?\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*['"]\?@ display contained contains=pythonType,pythonString nextgroup=pythonTypeUnion
182
+    syn match pythonTypeAnnoReturn @->\s*['"]\?\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\)*['"]\?@ display contains=pythonType,pythonString nextgroup=pythonTypeArgs
183
+    syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonString,pythonTypeArgs
184
+    syn keyword pythonType Any AnyStr Callable ClassVar Tuple Union Optional Type TypeVar None contained
185
+    syn keyword pythonType AbstractSet MutableSet Mapping MutableMapping Sequence MutableSequence ByteString Deque List contained
186
+    syn keyword pythonType Set FrozenSet MappingView KeysView ItemsView ValuesView Awaitable Coroutine AsyncIterable contained
187
+    syn keyword pythonType AsyncIterator ContextManager Dict DefaultDict Generator AsyncGenerator Text NamedTuple contained
188
+    syn keyword pythonType Iterable Iterator Reversible SupportsInt SupportsFloat SupportsAbs SupportsRound Container contained
189
+    syn keyword pythonType Hashable Sized Collection contained
190
+  endif
191
+endif
168
 
192
 
169
 syn match pythonStatement   "\<yield\>" display
193
 syn match pythonStatement   "\<yield\>" display
170
 syn match pythonImport      "\<from\>" display
194
 syn match pythonImport      "\<from\>" display
176
   syn keyword pythonImport      as
200
   syn keyword pythonImport      as
177
   syn match   pythonFunction    "[a-zA-Z_][a-zA-Z0-9_]*" display contained
201
   syn match   pythonFunction    "[a-zA-Z_][a-zA-Z0-9_]*" display contained
178
 else
202
 else
179
-  syn keyword pythonStatement   as nonlocal None
203
+  syn keyword pythonStatement   as nonlocal
180
   syn match   pythonStatement   "\<yield\s\+from\>" display
204
   syn match   pythonStatement   "\<yield\s\+from\>" display
181
-  syn keyword pythonBoolean     True False
182
-  syn match   pythonFunction    "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contained
183
-  syn keyword pythonStatement   await
184
-  syn match   pythonStatement   "\<async\s\+def\>" nextgroup=pythonFunction skipwhite
205
+  syn keyword pythonBuiltinObj  None True False
206
+  syn match   pythonFunction    "\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" nextgroup=pythonFuncArgs display contained
207
+  syn keyword pythonStatement   await async
208
+  syn match   pythonStatement   "\<async\s\+def\>" display nextgroup=pythonFunction skipwhite
185
   syn match   pythonStatement   "\<async\s\+with\>" display
209
   syn match   pythonStatement   "\<async\s\+with\>" display
186
   syn match   pythonStatement   "\<async\s\+for\>" display
210
   syn match   pythonStatement   "\<async\s\+for\>" display
187
 endif
211
 endif
188
 
212
 
213
+syn cluster pythonTypeExpression contains=pythonTypeAnno,pythonTypeUnion,pythonTypeArgs
214
+
215
+syn cluster pythonExpression contains=
216
+            \ pythonFuncArgs,
217
+            \ pythonDictSetExpr,
218
+            \ pythonListSliceExpr,
219
+            \ pythonLambdaExpr,
220
+            \ pythonStatement,
221
+            \ pythonRepeat,
222
+            \ pythonConditional,
223
+            \ pythonComment,
224
+            \ pythonOperator,
225
+            \ pythonNumber,
226
+            \ pythonNumberError,
227
+            \ pythonFloat,
228
+            \ pythonHexNumber,
229
+            \ pythonOctNumber,
230
+            \ pythonBytes,
231
+            \ pythonString,
232
+            \ pythonRawString,
233
+            \ pythonUniString,
234
+            \ pythonUniRawString,
235
+            \ pythonFString,
236
+            \ pythonExClass,
237
+            \ pythonBuiltinObj,
238
+            \ pythonBuiltinFunc
239
+
240
+syn cluster pythonFExpression contains=
241
+            \ pythonStatement,
242
+            \ pythonDictSetExpr,
243
+            \ pythonListSliceExpr,
244
+            \ pythonLambdaExpr,
245
+            \ pythonRepeat,
246
+            \ pythonConditional,
247
+            \ pythonOperator,
248
+            \ pythonNumber,
249
+            \ pythonHexNumber,
250
+            \ pythonOctNumber,
251
+            \ pythonBinNumber,
252
+            \ pythonFloat,
253
+            \ pythonString,
254
+            \ pythonBytes,
255
+            \ pythonBuiltinObj,
256
+            \ pythonBuiltinFunc
257
+
189
 "
258
 "
190
 " Decorators (new in Python 2.4)
259
 " Decorators (new in Python 2.4)
191
 "
260
 "
192
 
261
 
193
-syn match   pythonDecorator	"@" display nextgroup=pythonDottedName skipwhite
262
+syn match   pythonDecorator     "^\s*\zs@" display nextgroup=pythonDottedName skipwhite
194
 if s:Python2Syntax()
263
 if s:Python2Syntax()
195
   syn match   pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained
264
   syn match   pythonDottedName "[a-zA-Z_][a-zA-Z0-9_]*\%(\.[a-zA-Z_][a-zA-Z0-9_]*\)*" display contained
196
 else
265
 else
202
 " Comments
271
 " Comments
203
 "
272
 "
204
 
273
 
205
-syn match   pythonComment	"#.*$" display contains=pythonTodo,@Spell
274
+syn match   pythonComment       "#.*$" display contains=pythonTodo,@Spell
206
 if !s:Enabled("g:python_highlight_file_headers_as_comments")
275
 if !s:Enabled("g:python_highlight_file_headers_as_comments")
207
-  syn match   pythonRun		"\%^#!.*$"
208
-  syn match   pythonCoding	"\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
276
+  syn match   pythonRun         "\%^#!.*$"
277
+  syn match   pythonCoding      "\%^.*\%(\n.*\)\?#.*coding[:=]\s*[0-9A-Za-z-_.]\+.*$"
209
 endif
278
 endif
210
-syn keyword pythonTodo		TODO FIXME XXX contained
279
+syn keyword pythonTodo          TODO FIXME XXX contained
211
 
280
 
212
 "
281
 "
213
 " Errors
282
 " Errors
214
 "
283
 "
215
 
284
 
216
-syn match pythonError		"\<\d\+\D\+\>" display
217
-syn match pythonError		"[$?]" display
218
-syn match pythonError		"[&|]\{2,}" display
219
-syn match pythonError		"[=]\{3,}" display
285
+syn match pythonError           "\<\d\+\D\+\>" display
286
+syn match pythonError           "[$?]" display
287
+syn match pythonError           "[&|]\{2,}" display
288
+syn match pythonError           "[=]\{3,}" display
220
 
289
 
221
 " Mixing spaces and tabs also may be used for pretty formatting multiline
290
 " Mixing spaces and tabs also may be used for pretty formatting multiline
222
 " statements
291
 " statements
223
 if s:Enabled("g:python_highlight_indent_errors")
292
 if s:Enabled("g:python_highlight_indent_errors")
224
-  syn match pythonIndentError	"^\s*\%( \t\|\t \)\s*\S"me=e-1 display
293
+  syn match pythonIndentError   "^\s*\%( \t\|\t \)\s*\S"me=e-1 display
225
 endif
294
 endif
226
 
295
 
227
 " Trailing space errors
296
 " Trailing space errors
228
 if s:Enabled("g:python_highlight_space_errors")
297
 if s:Enabled("g:python_highlight_space_errors")
229
-  syn match pythonSpaceError	"\s\+$" display
298
+  syn match pythonSpaceError    "\s\+$" display
230
 endif
299
 endif
231
 
300
 
232
 "
301
 "
241
   syn region pythonString   start=+[bB]\='''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
310
   syn region pythonString   start=+[bB]\='''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
242
 else
311
 else
243
   " Python 3 byte strings
312
   " Python 3 byte strings
244
-  syn region pythonBytes		start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
245
-  syn region pythonBytes		start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
246
-  syn region pythonBytes		start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
247
-  syn region pythonBytes		start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
313
+  syn region pythonBytes                start=+[bB]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
314
+  syn region pythonBytes                start=+[bB]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesError,pythonBytesContent,@Spell
315
+  syn region pythonBytes                start=+[bB]"""+ end=+"""+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest2,pythonSpaceError,@Spell
316
+  syn region pythonBytes                start=+[bB]'''+ end=+'''+ keepend contains=pythonBytesError,pythonBytesContent,pythonDocTest,pythonSpaceError,@Spell
248
 
317
 
249
   syn match pythonBytesError    ".\+" display contained
318
   syn match pythonBytesError    ".\+" display contained
250
   syn match pythonBytesContent  "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError
319
   syn match pythonBytesContent  "[\u0000-\u00ff]\+" display contained contains=pythonBytesEscape,pythonBytesEscapeError
276
   syn region pythonString   start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
345
   syn region pythonString   start=+"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
277
   syn region pythonString   start=+"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
346
   syn region pythonString   start=+"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
278
   syn region pythonString   start=+'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
347
   syn region pythonString   start=+'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
348
+
349
+  syn region pythonFString  start=+[fF]'+ skip=+\\\\\|\\'\|\\$+ excludenl end=+'+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
350
+  syn region pythonFString  start=+[fF]"+ skip=+\\\\\|\\"\|\\$+ excludenl end=+"+ end=+$+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,@Spell
351
+  syn region pythonFString  start=+[fF]"""+ end=+"""+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest2,pythonSpaceError,@Spell
352
+  syn region pythonFString  start=+[fF]'''+ end=+'''+ keepend contains=pythonBytesEscape,pythonBytesEscapeError,pythonUniEscape,pythonUniEscapeError,pythonDocTest,pythonSpaceError,@Spell
279
 endif
353
 endif
280
 
354
 
281
 if s:Python2Syntax()
355
 if s:Python2Syntax()
312
 if s:Enabled("g:python_highlight_string_formatting")
386
 if s:Enabled("g:python_highlight_string_formatting")
313
   " % operator string formatting
387
   " % operator string formatting
314
   if s:Python2Syntax()
388
   if s:Python2Syntax()
315
-    syn match pythonStrFormatting	"%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
316
-    syn match pythonStrFormatting	"%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
389
+    syn match pythonStrFormatting       "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
390
+    syn match pythonStrFormatting       "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
317
   else
391
   else
318
-    syn match pythonStrFormatting	"%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
319
-    syn match pythonStrFormatting	"%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
392
+    syn match pythonStrFormatting       "%\%(([^)]\+)\)\=[-#0 +]*\d*\%(\.\d\+\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
393
+    syn match pythonStrFormatting       "%[-#0 +]*\%(\*\|\d\+\)\=\%(\.\%(\*\|\d\+\)\)\=[hlL]\=[diouxXeEfFgGcrs%]" contained containedin=pythonString,pythonRawString
320
   endif
394
   endif
321
 endif
395
 endif
322
 
396
 
324
   " str.format syntax
398
   " str.format syntax
325
   if s:Python2Syntax()
399
   if s:Python2Syntax()
326
     syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
400
     syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
327
-    syn match pythonStrFormat	"{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
401
+    syn match pythonStrFormat   "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
328
   else
402
   else
329
     syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString
403
     syn match pythonStrFormat "{{\|}}" contained containedin=pythonString,pythonRawString
330
-    syn match pythonStrFormat	"{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
404
+    syn match pythonStrFormat "{\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)\=\%(\.\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\[\%(\d\+\|[^!:\}]\+\)\]\)*\%(![rsa]\)\=\%(:\%({\%(\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*\|\d\+\)}\|\%([^}]\=[<>=^]\)\=[ +-]\=#\=0\=\d*,\=\%(\.\d\+\)\=[bcdeEfFgGnosxX%]\=\)\=\)\=}" contained containedin=pythonString,pythonRawString
405
+    syn region pythonStrInterpRegion matchgroup=pythonStrInterpRegion start="{" end="}" extend contained containedin=pythonFString contains=@pythonFExpression
331
   endif
406
   endif
332
 endif
407
 endif
333
 
408
 
334
 if s:Enabled("g:python_highlight_string_templates")
409
 if s:Enabled("g:python_highlight_string_templates")
335
   " string.Template format
410
   " string.Template format
336
   if s:Python2Syntax()
411
   if s:Python2Syntax()
337
-    syn match pythonStrTemplate	"\$\$" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
338
-    syn match pythonStrTemplate	"\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
339
-    syn match pythonStrTemplate	"\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
412
+    syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
413
+    syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
414
+    syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonUniString,pythonUniRawString,pythonRawString
340
   else
415
   else
341
-    syn match pythonStrTemplate	"\$\$" contained containedin=pythonString,pythonRawString
342
-    syn match pythonStrTemplate	"\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString
343
-    syn match pythonStrTemplate	"\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString
416
+    syn match pythonStrTemplate "\$\$" contained containedin=pythonString,pythonRawString
417
+    syn match pythonStrTemplate "\${[a-zA-Z_][a-zA-Z0-9_]*}" contained containedin=pythonString,pythonRawString
418
+    syn match pythonStrTemplate "\$[a-zA-Z_][a-zA-Z0-9_]*" contained containedin=pythonString,pythonRawString
344
   endif
419
   endif
345
 endif
420
 endif
346
 
421
 
347
 if s:Enabled("g:python_highlight_doctests")
422
 if s:Enabled("g:python_highlight_doctests")
348
   " DocTests
423
   " DocTests
349
-  syn region pythonDocTest	start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
350
-  syn region pythonDocTest2	start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
424
+  syn region pythonDocTest      start="^\s*>>>" end=+'''+he=s-1 end="^\s*$" contained
425
+  syn region pythonDocTest2     start="^\s*>>>" end=+"""+he=s-1 end="^\s*$" contained
351
 endif
426
 endif
352
 
427
 
353
 "
428
 "
355
 "
430
 "
356
 
431
 
357
 if s:Python2Syntax()
432
 if s:Python2Syntax()
358
-  syn match   pythonHexError	"\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>" display
359
-  syn match   pythonOctError	"\<0[oO]\=\o*\D\+\d*[lL]\=\>" display
360
-  syn match   pythonBinError	"\<0[bB][01]*\D\+\d*[lL]\=\>" display
433
+  syn match   pythonHexError    "\<0[xX]\x*[g-zG-Z]\+\x*[lL]\=\>" display
434
+  syn match   pythonOctError    "\<0[oO]\=\o*\D\+\d*[lL]\=\>" display
435
+  syn match   pythonBinError    "\<0[bB][01]*\D\+\d*[lL]\=\>" display
361
 
436
 
362
-  syn match   pythonHexNumber	"\<0[xX]\x\+[lL]\=\>" display
437
+  syn match   pythonHexNumber   "\<0[xX]\x\+[lL]\=\>" display
363
   syn match   pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display
438
   syn match   pythonOctNumber "\<0[oO]\o\+[lL]\=\>" display
364
   syn match   pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display
439
   syn match   pythonBinNumber "\<0[bB][01]\+[lL]\=\>" display
365
 
440
 
366
-  syn match   pythonNumberError	"\<\d\+\D[lL]\=\>" display
367
-  syn match   pythonNumber	"\<\d[lL]\=\>" display
368
-  syn match   pythonNumber	"\<[0-9]\d\+[lL]\=\>" display
369
-  syn match   pythonNumber	"\<\d\+[lLjJ]\>" display
441
+  syn match   pythonNumberError "\<\d\+\D[lL]\=\>" display
442
+  syn match   pythonNumber      "\<\d[lL]\=\>" display
443
+  syn match   pythonNumber      "\<[0-9]\d\+[lL]\=\>" display
444
+  syn match   pythonNumber      "\<\d\+[lLjJ]\>" display
370
 
445
 
371
-  syn match   pythonOctError	"\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display
372
-  syn match   pythonBinError	"\<0[bB][01]*[2-9]\d*[lL]\=\>" display
446
+  syn match   pythonOctError    "\<0[oO]\=\o*[8-9]\d*[lL]\=\>" display
447
+  syn match   pythonBinError    "\<0[bB][01]*[2-9]\d*[lL]\=\>" display
448
+
449
+  syn match   pythonFloat       "\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" display
450
+  syn match   pythonFloat       "\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
451
+  syn match   pythonFloat       "\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
373
 else
452
 else
374
-  syn match   pythonHexError	"\<0[xX]\x*[g-zG-Z]\x*\>" display
375
-  syn match   pythonOctError	"\<0[oO]\=\o*\D\+\d*\>" display
376
-  syn match   pythonBinError	"\<0[bB][01]*\D\+\d*\>" display
377
-
378
-  syn match   pythonHexNumber	"\<0[xX]\x\+\>" display
379
-  syn match   pythonOctNumber "\<0[oO]\o\+\>" display
380
-  syn match   pythonBinNumber "\<0[bB][01]\+\>" display
381
-
382
-  syn match   pythonNumberError	"\<\d\+\D\>" display
383
-  syn match   pythonNumberError	"\<0\d\+\>" display
384
-  syn match   pythonNumber	"\<\d\>" display
385
-  syn match   pythonNumber	"\<[1-9]\d\+\>" display
386
-  syn match   pythonNumber	"\<\d\+[jJ]\>" display
387
-
388
-  syn match   pythonOctError	"\<0[oO]\=\o*[8-9]\d*\>" display
389
-  syn match   pythonBinError	"\<0[bB][01]*[2-9]\d*\>" display
453
+  syn match   pythonHexError    "\<0[xX]\x*[g-zG-Z]\x*\>" display
454
+  syn match   pythonOctError    "\<0[oO]\=\o*\D\+\d*\>" display
455
+  syn match   pythonBinError    "\<0[bB][01]*\D\+\d*\>" display
456
+
457
+  syn match   pythonHexNumber   "\<0[xX][_0-9a-fA-F]*\x\>" display
458
+  syn match   pythonOctNumber "\<0[oO][_0-7]*\o\>" display
459
+  syn match   pythonBinNumber "\<0[bB][_01]*[01]\>" display
460
+
461
+  syn match   pythonNumberError "\<\d[_0-9]*\D\>" display
462
+  syn match   pythonNumberError "\<0[_0-9]\+\>" display
463
+  syn match   pythonNumberError "\<\d[_0-9]*_\>" display
464
+  syn match   pythonNumber      "\<\d\>" display
465
+  syn match   pythonNumber      "\<[1-9][_0-9]*\d\>" display
466
+  syn match   pythonNumber      "\<\d[jJ]\>" display
467
+  syn match   pythonNumber      "\<[1-9][_0-9]*\d[jJ]\>" display
468
+
469
+  syn match   pythonOctError    "\<0[oO]\=\o*[8-9]\d*\>" display
470
+  syn match   pythonBinError    "\<0[bB][01]*[2-9]\d*\>" display
471
+
472
+  syn match   pythonFloat       "\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=\>" display
473
+  syn match   pythonFloat       "\<\d\%([_0-9]*\d\)\=[eE][+-]\=\d\%([_0-9]*\d\)\=[jJ]\=\>" display
474
+  syn match   pythonFloat       "\<\d\%([_0-9]*\d\)\=\.\d\%([_0-9]*\d\)\=\%([eE][+-]\=\d\%([_0-9]*\d\)\=\)\=[jJ]\=" display
390
 endif
475
 endif
391
 
476
 
392
-syn match   pythonFloat		"\.\d\+\%([eE][+-]\=\d\+\)\=[jJ]\=\>" display
393
-syn match   pythonFloat		"\<\d\+[eE][+-]\=\d\+[jJ]\=\>" display
394
-syn match   pythonFloat		"\<\d\+\.\d*\%([eE][+-]\=\d\+\)\=[jJ]\=" display
395
-
396
 "
477
 "
397
 " Builtin objects and types
478
 " Builtin objects and types
398
 "
479
 "
399
 
480
 
400
 if s:Enabled("g:python_highlight_builtin_objs")
481
 if s:Enabled("g:python_highlight_builtin_objs")
401
   if s:Python2Syntax()
482
   if s:Python2Syntax()
402
-    syn keyword pythonBuiltinObj	None
403
-    syn keyword pythonBoolean		True False
483
+    syn keyword pythonBuiltinObj        None False True
404
   endif
484
   endif
405
-  syn keyword pythonBuiltinObj	Ellipsis NotImplemented
406
-  syn keyword pythonBuiltinObj	__debug__ __doc__ __file__ __name__ __package__
485
+  syn keyword pythonBuiltinObj  Ellipsis NotImplemented self cls
486
+  syn keyword pythonBuiltinObj  __debug__ __doc__ __file__ __name__ __package__
407
 endif
487
 endif
408
 
488
 
409
 "
489
 "
412
 
492
 
413
 if s:Enabled("g:python_highlight_builtin_funcs")
493
 if s:Enabled("g:python_highlight_builtin_funcs")
414
   if s:Python2Syntax()
494
   if s:Python2Syntax()
415
-    syn keyword pythonBuiltinFunc	apply basestring buffer callable coerce
416
-    syn keyword pythonBuiltinFunc	execfile file help intern long raw_input
417
-    syn keyword pythonBuiltinFunc	reduce reload unichr unicode xrange
495
+    syn match pythonBuiltinFunc '\v(\.)@<!\zs<(apply|basestring|buffer|callable|coerce)>\ze\(' nextgroup=pythonFuncArgs
496
+    syn match pythonBuiltinFunc '\v(\.)@<!\zs<(execfile|file|help|intern|long|raw_input)>\ze\(' nextgroup=pythonFuncArgs
497
+    syn match pythonBuiltinFunc '\v(\.)@<!\zs<(reduce|reload|unichr|unicode|xrange)>\ze\(' nextgroup=pythonFuncArgs
418
     if s:Enabled("g:python_print_as_function")
498
     if s:Enabled("g:python_print_as_function")
419
-      syn keyword pythonBuiltinFunc	print
499
+      syn match pythonBuiltinFunc       '\v(\.)@<!\zs<(print)>\ze\(' nextgroup=pythonFuncArgs
420
     endif
500
     endif
421
   else
501
   else
422
-    syn keyword pythonBuiltinFunc	ascii exec memoryview print
502
+    syn match pythonBuiltinFunc '\v(\.)@<!\zs<(ascii|exec|memoryview|print)\ze\(' nextgroup=pythonFuncArgs
423
   endif
503
   endif
424
-  syn keyword pythonBuiltinFunc	__import__ abs all any
425
-  syn keyword pythonBuiltinFunc	bin bool bytearray bytes
426
-  syn keyword pythonBuiltinFunc	chr classmethod cmp compile complex
427
-  syn keyword pythonBuiltinFunc	delattr dict dir divmod enumerate eval
428
-  syn keyword pythonBuiltinFunc	filter float format frozenset getattr
429
-  syn keyword pythonBuiltinFunc	globals hasattr hash hex id
430
-  syn keyword pythonBuiltinFunc	input int isinstance
431
-  syn keyword pythonBuiltinFunc	issubclass iter len list locals map max
432
-  syn keyword pythonBuiltinFunc	min next object oct open ord
433
-  syn keyword pythonBuiltinFunc	pow property range
434
-  syn keyword pythonBuiltinFunc	repr reversed round set setattr
435
-  syn keyword pythonBuiltinFunc	slice sorted staticmethod str sum super tuple
436
-  syn keyword pythonBuiltinFunc	type vars zip
504
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(__import__|abs|all|any)>\ze\(' nextgroup=pythonFuncArgs
505
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(bin|bool|bytearray|bytes)>\ze\(' nextgroup=pythonFuncArgs
506
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(chr|classmethod|cmp|compile|complex)>\ze\(' nextgroup=pythonFuncArgs
507
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(delattr|dict|dir|divmod|enumerate|eval)>\ze\(' nextgroup=pythonFuncArgs
508
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(filter|float|format|frozenset|getattr)>\ze\(' nextgroup=pythonFuncArgs
509
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(globals|hasattr|hash|hex|id)>\ze\(' nextgroup=pythonFuncArgs
510
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(input|int|isinstance)>\ze\(' nextgroup=pythonFuncArgs
511
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(issubclass|iter|len|list|locals|map|max)>\ze\(' nextgroup=pythonFuncArgs
512
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(min|next|object|oct|open|ord)>\ze\(' nextgroup=pythonFuncArgs
513
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(pow|property|range)>\ze\(' nextgroup=pythonFuncArgs
514
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(repr|reversed|round|set|setattr)>\ze\(' nextgroup=pythonFuncArgs
515
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(slice|sorted|staticmethod|str|sum|super|tuple)>\ze\(' nextgroup=pythonFuncArgs
516
+  syn match pythonBuiltinFunc   '\v(\.)@<!\zs<(type|vars|zip)>\ze\(' nextgroup=pythonFuncArgs
437
 endif
517
 endif
438
 
518
 
439
 "
519
 "
442
 
522
 
443
 if s:Enabled("g:python_highlight_exceptions")
523
 if s:Enabled("g:python_highlight_exceptions")
444
   if s:Python2Syntax()
524
   if s:Python2Syntax()
445
-    syn keyword pythonExClass	StandardError
525
+    syn keyword pythonExClass   StandardError nextgroup=pythonFuncArgs
446
   else
526
   else
447
-    syn keyword pythonExClass	BlockingIOError ChildProcessError
448
-    syn keyword pythonExClass	ConnectionError BrokenPipeError
449
-    syn keyword pythonExClass	ConnectionAbortedError ConnectionRefusedError
450
-    syn keyword pythonExClass	ConnectionResetError FileExistsError
451
-    syn keyword pythonExClass	FileNotFoundError InterruptedError
452
-    syn keyword pythonExClass	IsADirectoryError NotADirectoryError
453
-    syn keyword pythonExClass	PermissionError ProcessLookupError TimeoutError
454
-
455
-    syn keyword pythonExClass	ResourceWarning
527
+    syn keyword pythonExClass   BlockingIOError ChildProcessError nextgroup=pythonFuncArgs
528
+    syn keyword pythonExClass   ConnectionError BrokenPipeError nextgroup=pythonFuncArgs
529
+    syn keyword pythonExClass   ConnectionAbortedError ConnectionRefusedError nextgroup=pythonFuncArgs
530
+    syn keyword pythonExClass   ConnectionResetError FileExistsError nextgroup=pythonFuncArgs
531
+    syn keyword pythonExClass   FileNotFoundError InterruptedError nextgroup=pythonFuncArgs
532
+    syn keyword pythonExClass   IsADirectoryError NotADirectoryError nextgroup=pythonFuncArgs
533
+    syn keyword pythonExClass   PermissionError ProcessLookupError TimeoutError nextgroup=pythonFuncArgs
534
+
535
+    syn keyword pythonExClass   ResourceWarning nextgroup=pythonFuncArgs
456
   endif
536
   endif
457
-  syn keyword pythonExClass	BaseException
458
-  syn keyword pythonExClass	Exception ArithmeticError
459
-  syn keyword pythonExClass	LookupError EnvironmentError
460
-
461
-  syn keyword pythonExClass	AssertionError AttributeError BufferError EOFError
462
-  syn keyword pythonExClass	FloatingPointError GeneratorExit IOError
463
-  syn keyword pythonExClass	ImportError IndexError KeyError
464
-  syn keyword pythonExClass	KeyboardInterrupt MemoryError NameError
465
-  syn keyword pythonExClass	NotImplementedError OSError OverflowError
466
-  syn keyword pythonExClass	ReferenceError RuntimeError StopIteration
467
-  syn keyword pythonExClass	SyntaxError IndentationError TabError
468
-  syn keyword pythonExClass	SystemError SystemExit TypeError
469
-  syn keyword pythonExClass	UnboundLocalError UnicodeError
470
-  syn keyword pythonExClass	UnicodeEncodeError UnicodeDecodeError
471
-  syn keyword pythonExClass	UnicodeTranslateError ValueError VMSError
472
-  syn keyword pythonExClass	WindowsError ZeroDivisionError
473
-
474
-  syn keyword pythonExClass	Warning UserWarning BytesWarning DeprecationWarning
475
-  syn keyword pythonExClass	PendingDepricationWarning SyntaxWarning
476
-  syn keyword pythonExClass	RuntimeWarning FutureWarning
477
-  syn keyword pythonExClass	ImportWarning UnicodeWarning
537
+  syn keyword pythonExClass     BaseException nextgroup=pythonFuncArgs
538
+  syn keyword pythonExClass     Exception ArithmeticError nextgroup=pythonFuncArgs
539
+  syn keyword pythonExClass     LookupError EnvironmentError nextgroup=pythonFuncArgs
540
+
541
+  syn keyword pythonExClass     AssertionError AttributeError BufferError EOFError nextgroup=pythonFuncArgs
542
+  syn keyword pythonExClass     FloatingPointError GeneratorExit IOError nextgroup=pythonFuncArgs
543
+  syn keyword pythonExClass     ImportError IndexError KeyError nextgroup=pythonFuncArgs
544
+  syn keyword pythonExClass     KeyboardInterrupt MemoryError NameError nextgroup=pythonFuncArgs
545
+  syn keyword pythonExClass     NotImplementedError OSError OverflowError nextgroup=pythonFuncArgs
546
+  syn keyword pythonExClass     ReferenceError RuntimeError StopIteration nextgroup=pythonFuncArgs
547
+  syn keyword pythonExClass     SyntaxError IndentationError TabError nextgroup=pythonFuncArgs
548
+  syn keyword pythonExClass     SystemError SystemExit TypeError nextgroup=pythonFuncArgs
549
+  syn keyword pythonExClass     UnboundLocalError UnicodeError nextgroup=pythonFuncArgs
550
+  syn keyword pythonExClass     UnicodeEncodeError UnicodeDecodeError nextgroup=pythonFuncArgs
551
+  syn keyword pythonExClass     UnicodeTranslateError ValueError VMSError nextgroup=pythonFuncArgs
552
+  syn keyword pythonExClass     WindowsError ZeroDivisionError nextgroup=pythonFuncArgs
553
+
554
+  syn keyword pythonExClass     Warning UserWarning BytesWarning DeprecationWarning nextgroup=pythonFuncArgs
555
+  syn keyword pythonExClass     PendingDepricationWarning SyntaxWarning nextgroup=pythonFuncArgs
556
+  syn keyword pythonExClass     RuntimeWarning FutureWarning nextgroup=pythonFuncArgs
557
+  syn keyword pythonExClass     ImportWarning UnicodeWarning nextgroup=pythonFuncArgs
478
 endif
558
 endif
479
 
559
 
480
 if s:Enabled("g:python_slow_sync")
560
 if s:Enabled("g:python_slow_sync")
496
   endif
576
   endif
497
 
577
 
498
   HiLink pythonStatement        Statement
578
   HiLink pythonStatement        Statement
579
+  HiLink pythonLambdaExpr       Statement
499
   HiLink pythonImport           Include
580
   HiLink pythonImport           Include
500
   HiLink pythonFunction         Function
581
   HiLink pythonFunction         Function
501
   HiLink pythonConditional      Conditional
582
   HiLink pythonConditional      Conditional
536
     HiLink pythonBytesError         Error
617
     HiLink pythonBytesError         Error
537
     HiLink pythonBytesEscape        Special
618
     HiLink pythonBytesEscape        Special
538
     HiLink pythonBytesEscapeError   Error
619
     HiLink pythonBytesEscapeError   Error
620
+    HiLink pythonFString            String
621
+    HiLink pythonStrInterpRegion    Special
539
   endif
622
   endif
540
 
623
 
541
   HiLink pythonStrFormatting    Special
624
   HiLink pythonStrFormatting    Special
555
   HiLink pythonHexError         Error
638
   HiLink pythonHexError         Error
556
   HiLink pythonBinError         Error
639
   HiLink pythonBinError         Error
557
 
640
 
558
-  HiLink pythonBoolean          Boolean
559
-
560
   HiLink pythonBuiltinObj       Structure
641
   HiLink pythonBuiltinObj       Structure
561
   HiLink pythonBuiltinFunc      Function
642
   HiLink pythonBuiltinFunc      Function
562
 
643
 
563
   HiLink pythonExClass          Structure
644
   HiLink pythonExClass          Structure
564
 
645
 
646
+  HiLink pythonTypeAnno         Optional
647
+  HiLink pythonTypeUnion        Optional
648
+  HiLink pythonTypeAnnoReturn   Optional
649
+  HiLink pythonTypeArgs         Optional
650
+  HiLink pythonType             Special
651
+
565
   delcommand HiLink
652
   delcommand HiLink
653
+
654
+  " default style for custom highlight group (may be overriden in colors)
655
+  hi Optional gui=italic cterm=italic
566
 endif
656
 endif
567
 
657
 
568
 let b:current_syntax = "python"
658
 let b:current_syntax = "python"

+ 48
- 10
test.py View File

8
 
8
 
9
 # Keywords.
9
 # Keywords.
10
 
10
 
11
-with break continue del exec return pass print raise global assert lambda yield
11
+with break continue del exec return pass print raise global assert yield
12
 for while if elif else import from as try except finally and in is not or
12
 for while if elif else import from as try except finally and in is not or
13
 
13
 
14
+lambda: a + 1
15
+lambda x, y: x + y
16
+
14
 yield from
17
 yield from
15
 
18
 
16
 def functionname
19
 def functionname
23
 async with
26
 async with
24
 async for
27
 async for
25
 
28
 
29
+# Type annotations
30
+
31
+def myfunc(a: str, something_other,
32
+           b: Callable[[str, str], int],
33
+           c: mypkg.MyType) -> 'runtime_resolved_type':
34
+    myval: float
35
+    mygood: Optional[int, Any] = b('wow', 'oops')
36
+    myarr: Sequence[int] = origarr[aa:bb] + (lambda: x)()
37
+    mykey = a
38
+    wow = {
39
+        mykey: this_should_not_be_type_anno[Any],
40
+        'b': some_data,
41
+    }
42
+    call_with_dict(a={
43
+        'a': asdf,
44
+        'b': 'zxcb',
45
+        mykey: this_should_not_be_type_anno[Any],
46
+    }, b=mydata['a'])
47
+    vanilla_lambda = lambda x, y: myval + 1.0
48
+    call_with_lambda(lambda x, y: myval + 1.0)
49
+    call_with_slice(mydata[range_start:range_end])
50
+
51
+
26
 # Builtin objects.
52
 # Builtin objects.
27
 
53
 
28
 True False Ellipsis None NotImplemented
54
 True False Ellipsis None NotImplemented
29
 
55
 
30
 # Builtin function and types.
56
 # Builtin function and types.
31
 
57
 
32
-__import__ abs all any apply basestring bool buffer callable chr classmethod
33
-cmp coerce compile complex delattr dict dir divmod enumerate eval execfile file
34
-filter float frozenset getattr globals hasattr hash help hex id input int
35
-intern isinstance issubclass iter len list locals long map max min object oct
36
-open ord pow property range raw_input reduce reload repr reversed round set
37
-setattr slice sorted staticmethod str sum super tuple type unichr unicode vars
38
-xrange zip
58
+__import__() abs() all() any() apply() basestring() bool() buffer() callable() chr() classmethod()
59
+cmp() coerce() compile() complex() delattr() dict() dir() divmod() enumerate() eval() execfile() file()
60
+filter() float() frozenset() getattr() globals() hasattr() hash() help() hex() id() input() int()
61
+intern() isinstance() issubclass() iter() len() list() locals() long() map() max() min() object() oct()
62
+open() ord() pow() property() range() raw_input() reduce() reload() repr() reversed() round() set()
63
+setattr() slice() sorted() staticmethod() str() sum() super() tuple() type() unichr() unicode() vars()
64
+xrange() zip()
65
+
66
+when_we_dont_call = a.float
67
+float = when_we_dont_call
68
+
69
+when_we_call = float(x)
70
+when_we_call = min(a, b)
39
 
71
 
40
 # Builtin exceptions and warnings.
72
 # Builtin exceptions and warnings.
41
 
73
 
61
 
93
 
62
 # Numbers
94
 # Numbers
63
 
95
 
64
-0 1 2 9 10 0x1f .3 12.34 0j 0j 34.2E-3 0b10 0o77 1023434 0x0
96
+0 1 2 9 10 0x1f .3 12.34 0j 124j 34.2E-3 0b10 0o77 1023434 0x0
97
+1_1 1_1.2_2 1_2j 0x_1f 0x1_f 34_56e-3 34_56e+3_1 0o7_7
65
 
98
 
66
 # Erroneous numbers
99
 # Erroneous numbers
67
 
100
 
68
-077 100L 0xfffffffL 0L 08 0xk 0x  0b102 0o78 0o123LaB
101
+077 100L 0xfffffffL 0L 08 0xk 0x 0b102 0o78 0o123LaB
102
+0_ 0_1 0_x1f 0x1f_ 0_b77 0b77_ .2_ 1_j
69
 
103
 
70
 # Strings
104
 # Strings
71
 
105
 
103
 "${test} ${test ${test}aname $$$ $test+nope"
137
 "${test} ${test ${test}aname $$$ $test+nope"
104
 b"${test} ${test ${test}aname $$$ $test+nope"
138
 b"${test} ${test ${test}aname $$$ $test+nope"
105
 
139
 
140
+f"{var}...{arr[123]} normal {var['{'] // 0xff} \"xzcb\" 'xzcb' {var['}'] + 1} text"
141
+f"{expr1 if True or False else expr2} wow {','.join(c.lower() for c in 'asdf')}"
142
+f"hello {expr:.2f} yes {(lambda: 0b1)():#03x} lol {var!r}"
143
+
106
 # Doctests.
144
 # Doctests.
107
 
145
 
108
 """
146
 """