[英]How annotate a function that takes another function as parameter?
I'm experimenting with type annotations in Python.我正在尝试在 Python 中使用类型注释。 Most cases are pretty clear, except for those functions that take another function as parameter.大多数情况都非常清楚,除了那些将另一个函数作为参数的函数。
Consider the following example:考虑以下示例:
from __future__ import annotations
def func_a(p:int) -> int:
return p*5
def func_b(func) -> int: # How annotate this?
return func(3)
if __name__ == "__main__":
print(func_b(func_a))
The output simply prints 15
.输出只是打印15
。
How should I annotate the func
parameter in func_b( )
?我应该如何注释func_b( )
的func
参数?
Shouldn't it just be function
?它不应该只是function
吗?
>>> type(func_a)
function
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.