如何使multipledispatch接受同一类的对象(python)
我使用multipledispatch创建一个Point类,它有三个构造函数:一个接受一个整数,一个接受两个,还有一个接受Point类型的对象。但是我无法实现第三个构造函数,因为我不知道给如何使multipledispatch接受同一类的对象(python),python,overloading,multiple-dispatch,Python,Overloading,Multiple Dispatch,我使用multipledispatch创建一个Point类,它有三个构造函数:一个接受一个整数,一个接受两个,还有一个接受Point类型的对象。但是我无法实现第三个构造函数,因为我不知道给@dispatch装饰器提供什么参数,因为类点尚未定义。我目前已经求助于使用对象,但有什么方法可以使用Point本身吗 以下是我的(部分)代码: from multipledispatch import dispatch class Point: @dispatch(int,int) def
@dispatch
装饰器提供什么参数,因为类点
尚未定义。我目前已经求助于使用对象
,但有什么方法可以使用Point本身吗
以下是我的(部分)代码:
from multipledispatch import dispatch
class Point:
@dispatch(int,int)
def __init__(self, y = None,x = None):
self.y = y
self.x = x
@dispatch(int)
def __init__(self, yx = None):
self.__init__(yx,yx)
@dispatch(object) # is there any way I can use @dispatch(Point)?
def __init__(self, p: "Point") -> "Point": # using forward reference
self = p.copy()