我正在使用 multipledispatch 创建一个 Point 类,它具有三个构造函数:一个接受单个整数,一个接受两个整数,一个接受 Point 类型的对象。但是我无法实现第三个构造函数,因为我不知道该给@dispatch
装饰器什么参数,因为该类Point
尚未定义。我目前已经使用object
,但是有什么方法可以使用 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()