首页 > 解决方案 > How do I return type hinting defined types

问题描述

If I have the following:

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

Can I get somehow the specified type of my arguments?

I tried using func.__code__.co_varnames & inspect.getargspec(func) without good results.

标签: pythonpython-3.xtype-hinting

解决方案


blue_note 的答案不适__future__.annotations用于 python 3.7 中引入的 ,请改用typing.get_type_hints


推荐阅读