我使用以下格式记录我的Python代码:
def my_function(param: str) -> dict:
some code我不知道如何记录传递给另一个函数的函数。
例如:
def my_function(my_other_function: ???) -> dict:
some code我如何做一个函数注释?
发布于 2017-11-23 08:05:07
的第一个想法:“中的所有东西都是对象”
我在文档中找不到任何东西,但作为everything in python is an object,我会为object拍摄。
def my_function(my_other_function: object) -> dict:
some code为了证明这一点:
if isinstance(my_function, my_function, object):
print("yes")
>yes无论如何,这可能不太明确,因此:
秒思考:使用适当类型提示的
根据COLDSPEED注释的内容,一个更显式的类型提示将使用typing
import typing
def my_function(my_other_function:typing.Callable):->dict:
pass“注解的唯一方式就是由第三方库来解释它们”。这意味着,对于你的源代码本身,它不会改变任何东西。只是想提一下。
https://stackoverflow.com/questions/47450228
复制相似问题