我想在當前的Python 3.5項目中使用類型提示。我的函數應該接收一個函數作為參數。如何在類型提示中指定類型函數?import typingdef my_function(name:typing.AnyStr, func: typing.Function) -> None: # However, typing.Function does not exist. # How can I specify the type function for the parameter `func`? # do some processing pass我檢查了PEP 483,但在那里找不到函數類型提示。
2 回答

一只萌萌小番薯
TA貢獻1795條經驗 獲得超7個贊
另一個需要注意的有趣點是,您可以使用內置函數type()來獲取內置函數的類型并使用它。所以你可以
def f(my_function: type(abs)) -> int:
return my_function(100)
或那種形式的東西
添加回答
舉報
0/150
提交
取消