假设我有一个类似这样的类:
class FunctionCaller:
def __init__(self):
"""A class which can be used to call different functions which take the same
parameters
"""
self.f = lambda a,b: (a,b)
def setF(self, new_f):
"""Set the function to call
:param new_f: The new function this object should call
:type new_f: func(:class:`.SomeClass`, :class:`int`)
"""
self.f = new_f
def callF(self, a, b):
"""Call the function this object currently contains
:param a: Some value
:param b: Some other value
"""
return self.f(a,b)
class SomeClass:
"""Some class which does nothing
"""
pass
例如(忽略这可能是不好的编码风格这一事实),让我们假设FunctionCaller
将要调用的函数期望将SomeClass
作为第一个参数,并将一个int作为第二个参数。我希望文档显示这些东西的链接。我在示例中定义它的方式是有效的,但是看起来不太好。在
有没有一种方法可以使用:type:
说明符来指示参数是一个函数吗?在
我想您可以指定^{} 作为类型。但我建议你解释一下它是如何工作的:
相关问题 更多 >
编程相关推荐