该typing模块为泛型类型提示提供了一个基类:typing.Generic该类.
Generic方括号中的accept类型参数的子类,例如:
list_of_ints = typing.List[int]
str_to_bool_dict = typing.Dict[str, bool]
Run Code Online (Sandbox Code Playgroud)
我的问题是,如何访问这些类型的参数?
也就是说,str_to_bool_dict作为输入,我如何得到str和bool作为输出?
基本上我正在寻找一个这样的功能
>>> magic_function(str_to_bool_dict)
(<class 'str'>, <class 'bool'>)
Run Code Online (Sandbox Code Playgroud)