Pass class of its own type in constructor in python

Viewed 10

Ok, the title needs some work, but I'm not a native speaker. Anyways, I have a class in python (a language that I rarely use) and I have a constructor that takes an optional instance of the class itself, like so:

class ArmSegment:
    def __init__(self, length: float, angle: float, parent: ArmSegment):
        self.length = length
        self.angle = angle
        self.parent = parent

    def calc_endpoint(self) -> (float, float):
        # redacted for length

    def calc_actual_angle(self) -> float:
        if self.parent is None:
            return self.angle
        else:
            return self.angle + self.parent.calc_actual_angle()

This gives me an error, because ArmSegment hasn't been defined yet. How do I fix this?

0 Answers
Related