如果我有以下内容:
def alert(self, text: str, color: str) -> str:
我可以以某种方式获得我的参数的指定类型吗?
我尝试使用func.__code__.co_varnames
&inspect.getargspec(func)
没有良好的结果。
alert.__annotations__
具有类型的dict。
密钥return
描述了返回值。所有其他键是参数的名称。
blue_note的答案与python 3.7中引入的 __future__.annotations
不起作用,使用typing.get_type_hints代替。