When I define a class, how can I include arguments in its methods' signatures which have to be of the same class? I am building a graph structure which should work like this, but here is a simplified example:
class Dummy:
def __init__(self, value: int, previous: Dummy=None):
self._value = value
self._previous = previous
@property
def value(self):
return self._value
def plus_previous(self):
return self.value + self._previous.value
d1 = Dummy(7)
d2 = Dummy(3, d1)
d2.plus_previous()
This results in the following error:
NameError: name 'Dummy' is not defined
I mean, I can do it the Python 2 way, but I was hoping there is a more python-3-ic solution than this:
class Dummy:
def __init__(self, value: int, previous=None):
assert type(previous) is Dummy or previous is None
...