Type Hinting for objects of type that's being defined
<p>I get the error:</p>

<pre class="lang-none prettyprint-override"><code>NameError: name 'OrgUnit' is not defined
</code></pre>



<pre><code>class OrgUnit(object):

    def __init__(self,
                 an_org_name: str,
                 its_parent_org_unit: OrgUnit= None
                 ):
        self.org_unit_name = an_org_name
        self.parent_org_unit = its_parent_org_unit

    def __str__(self):
        if self.parent_org_unit:
            parent_org_unit_name = self.parent_org_unit.__str__()
            return parent_org_unit_name + "-&gt;" + self.org_unit_name
        else:
            return self.org_unit_name


if __name__ == '__main__':
    ibm_worldwide = OrgUnit("IBM_Worldwide")
    ibm_usa = OrgUnit("IBM_USA", ibm_worldwide)
    ibm_asia = OrgUnit("IBM_Asia", ibm_worldwide)
    ibm_china = OrgUnit("IBM_China", ibm_asia)
    print(ibm_worldwide)
    print(ibm_usa)
    print(ibm_asia)
    print(ibm_china)
</code></pre>

<p>I am sure this is a known paradigm, as it seems like a pretty common hierarchical class usage issue (a self referencing class). I know I could change the type of <code>its_parent_org_unit</code> to be <code>object</code> and it works, but this seems like the wrong thing to do, primarily since it scuppers my ability to check types in my calls. With <code>its_parent_org_unit</code> changed to be a type <code>object</code> I get the correct results:</p>

<pre><code>IBM_Worldwide
IBM_Worldwide-&gt;IBM_USA
IBM_Worldwide-&gt;IBM_Asia
IBM_Worldwide-&gt;IBM_Asia-&gt;IBM_China
</code></pre>

<p>I am open to thoughts and suggestions. What is the most "pythonic" way to do this sort of thing?</p>

<p>PS: What is the name for this sort of "self referencing class" paradigm/problem, which I could use to look up other suggestions? </p>