
typing 是在 python 3.5 才有的模块
Python 类型提示:https://cloud.tencent.com/developer/article/1864619
https://cloud.tencent.com/developer/article/1866298
https://www.cnblogs.com/poloyy/p/15153883.html
https://cloud.tencent.com/developer/article/1866296
https://cloud.tencent.com/developer/article/1866297
https://cloud.tencent.com/developer/article/1866293
# Any
from typing import Any
a = None # type: Any
a1 = [] # OK
a2 = 2 # OK
s = '' # type: str
s1 = a # OK
def foo(item: Any) -> int:
# Typechecks; 'item' 可以是任意类型
print(item)
return 1
foo(a)
foo(a1)
foo(a2)
foo(s)
foo(s1)def legacy_parser(text):
...
return data
# 上述写法等价于下述写法
# 所有没有返回类型或参数类型的函数将隐式默认使用 Any
def legacy_parser(text: Any) -> Any:
...
return data