如何返回类型提示定义的类型

时间:2019-07-01 09:51:28

标签: python python-3.x typehints

如果我具有以下条件:

def alert(self, text: str, color: str) -> str:

我能以某种方式获得指定类型的参数吗?

我尝试使用func.__code__.co_varnamesinspect.getargspec(func),但收效不佳。

2 个答案:

答案 0 :(得分:1)

date day Rude Staff Poor Hygiene Out of Stock 0 01/06/19 Sat 12 4 3 1 09/06/19 Sun 12 4 3 2 15/09/21 Fri 12 4 3 带有类型的字典。

alert.__annotations__描述返回值。所有其他键都是参数的名称。

答案 1 :(得分:1)

blue_note的答案不适用于python 3.7中引入的__future__.annotations,而应使用typing.get_type_hints

相关问题