该 前者是正确的 ,如果
arg接受一个 实例
CustomClass:
def FuncA(arg: CustomClass): # ^ instance of CustomClass
如果您想要 类CustomClass
本身(或子类型),则应编写:
from typing import Type # you have to import Typedef FuncA(arg: Type[CustomClass]): # ^ CustomClass (class object) itself
就像在有关 打字
的文档中写的那样:
**class typing.Type(Generic[CT_co])**带注释的变量
C可以接受type的值C。相反,带 注释Type[C]的变量 可以接受本身是类的值 -具体地说,它将接受的
类对象C。
该文档包含有关
int该类的示例:
a = 3 # Has type 'int'b = int # Has type 'Type[int]'c = type(a) # Also has type 'Type[int]'



