类型注释:从容器类型中提取内部类型

Type annotations: Extract inner type from container type

我有以下设置:

from typing import List
a = List[int]
foo(a) == int

我可以用什么 fooList 中得到 int

您可以使用属性 __args__ 来取出 int

from typing import List
a = List[int]
print(a.__args__[0])

结果:<class 'int'>