I am using multipledispatch to make a Point class, which has three constructors: one that takes a single integer, one that takes two, and one that takes an object of type Point. But I am unable to implement the third constructor as I don't know what argument to give to the @dispatch
decorator, since the class Point
is not yet defined. I have currently resorted to using object
, but is there any way I can use Point itself?
Here's (part of) my code:
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()
@dispatch(object)
and in the init method,if isinstance(p, Point): self = p.copy()
– Machmeter