소스 검색

Add support for runtime-resolved type annotations in strings

Joongi Kim 7 년 전
부모
커밋
daf7366c8d
2개의 변경된 파일4개의 추가작업 그리고 4개의 파일을 삭제
  1. 3
    3
      syntax/python.vim
  2. 1
    1
      test.py

+ 3
- 3
syntax/python.vim 파일 보기

@@ -174,9 +174,9 @@ syn region pythonFuncArgs    matchgroup=pythonFuncArgs    start='(' end=')' cont
174 174
 
175 175
 if !s:Python2Syntax()
176 176
   if s:Enabled("g:python_highlight_type_annotations")
177
-    syn match pythonTypeAnno ":\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*"hs=s+1 display contained contains=pythonType nextgroup=pythonTypeArgs
178
-    syn match pythonTypeAnnoReturn "->\s*\%([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\%([^[:cntrl:][:punct:][:space:]]\|_\)*" display contains=pythonType nextgroup=pythonTypeArgs
179
-    syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonTypeArgs
177
+    syn match pythonTypeAnno @:\s*['"]\?\([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\([^[:cntrl:][:punct:][:space:]]\|_\)*['"]\?@hs=s+1 display contained contains=pythonType,pythonString nextgroup=pythonTypeArgs
178
+    syn match pythonTypeAnnoReturn @->\s*['"]\?\([^[:cntrl:][:space:][:punct:][:digit:]]\|_\)\([^[:cntrl:][:punct:][:space:]]\|_\)*['"]\?@ display contains=pythonType,pythonString nextgroup=pythonTypeArgs
179
+    syn region pythonTypeArgs matchgroup=pythonTypeArgs start='\[' end='\]' display contained contains=pythonType,pythonString,pythonTypeArgs
180 180
     syn keyword pythonType Any AnyStr Callable ClassVar Tuple Union Optional Type TypeVar None contained
181 181
     syn keyword pythonType AbstractSet MutableSet Mapping MutableMapping Sequence MutableSequence ByteString Deque List contained
182 182
     syn keyword pythonType Set FrozenSet MappingView KeysView ItemsView ValuesView Awaitable Coroutine AsyncIterable contained

+ 1
- 1
test.py 파일 보기

@@ -29,7 +29,7 @@ async for
29 29
 # Type annotations
30 30
 
31 31
 def myfunc(a: str, something_other,
32
-           b: Callable[[str, str], int]) -> Any:
32
+           b: Callable[[str, str], int]) -> 'runtime_resolved_type':
33 33
     myval: float
34 34
     mygood: Optional[int, Any] = b('wow', 'oops')
35 35
     myarr: Sequence[int] = origarr[aa:bb] + (lambda: x)()