且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何获取函数的参数类型和返回类型?

更新时间:2023-11-11 16:51:52

Python 3 引入了函数注解.他们自己什么都不做,但您可以编写自己的执行:

Python 3 introduces function annotations. By themselves they don't do anything, but you can write your own enforcement:

def strict(fun):
    # inspect annotations and check types on call

@strict
def funcA(a: int, b: int) -> int:
    return a + b