Inspect params and return types

后端 未结 3 829
暖寄归人
暖寄归人 2021-01-13 21:26

Is it possible using Python 3 syntax for declaring input parameters and return value types determine those types? Similarly to determining the number of parameters of a func

3条回答
  •  失恋的感觉
    2021-01-13 22:10

    def foo(name: str) -> int:
        pass
    
    foo.__annotations__
    # {'name': , 'return': }
    
    foo.__annotations__['return'].__name__
    # 'int'
    

提交回复
热议问题