【发布时间】:2023-01-30 17:52:33
【问题描述】:
@overload
def setSize(self,size:tuple[int|str])->None:
'''
Set image size (width,height)
'''
try:self.options.append(f"width=\"{str(size[0])}\" height=\"{str(size[1])}\"")
except IndexError:print("Error reading the size, aborting")
@overload
def setSize(self,width:int|str,height:int|str)->None:
'''
Set image Size
'''
self.setSize((width,height))
这是我的代码,我将此函数称为 var.setSize((500,500)) 通常会调用最上面的一个,但我收到了这个错误:
NotImplementedError: You should not call an overloaded function. A series of @overload-decorated functions outside a stub module should always be followed by an implementation that is not @overload-ed.
【问题讨论】:
-
从错误消息来看,其中一个函数似乎必须在没有
@overload注释的情况下声明。你试过了吗? -
但是我怎么知道哪个会运行,它们不是满足其中一个参数实例的蓝图吗?
标签: python overloading