title: How do I make classes from a submodule available in a parent module's namespace?
body: <p>Here's a python module. <code>foo</code> is in <code>sys.path</code>.</p>
  
  <pre><code>foo\
      __init__.py
      bar\
          __init__.py
          base.py
              class Base(object)
          derived.py
              import foo.bar.base as base
              class Derived(base.Base)
  </code></pre>
  
  <p>I've got nothing fancy going on yet. If I want to instantiate the <strong>Derived</strong> class from the <code>derived</code> module, I can do that easily enough:</p>
  
  <pre><code>import foo.bar.derived as derived
  print(derived.Derived())
  </code></pre>
  
  <p>However, I'd like to just import the <code>bar</code> module and call <code>bar.Derived()</code>, because I plan to have lots of classes within lots of different modules, and I don't want to deal with all these tentacular import paths. My understanding is that I can simply import <strong>Derived</strong> into the namespace of the <code>bar</code> module, by modifying my project like so:</p>
  
  <pre><code>foo\
      __init__.py
      bar\
          __init__.py
              from foo.bar.derived import Derived
          base.py
              class Base(object)
          derived.py
              import foo.bar.base as base
              class Derived(base.Base)
  </code></pre>
  
  <p>Now I should be able to do the following:</p>
  
  <pre><code>import foo.bar as bar
  print(bar.Derived())
  </code></pre>
  
  <p>But I get an AttributeError complaining that the <code>foo</code> module has no submodule called <code>bar</code>:</p>
  
  <pre><code>test.py             (1): import foo.bar
  foo\bar\__init__.py (1): from foo.bar.derived import Derived
  foo\bar\derived.py  (1): import foo.bar.base as base
  
  AttributeError: 'module' object has no attribute 'bar'
  </code></pre>
  
  <p>In fact, my original test code (at top) doesn't work either! As soon as I try to import <code>foo.bar</code>, I get errors.</p>
  
  <p>What I can gleam from this error is that the import statement in <code>__init__.py</code> causes <code>derived.py</code> to be executed before <code>bar</code> is fully loaded, and therefore it can't import the module (also from <code>bar</code>) which contains its own base class. I'm coming from the C++ world, where ultra-nested namespaces aren't as integral and a simple forward declaration would negate this problem, but I've been led to believe that what I'm looking for is possible and at least a somewhat acceptably Pythonic solution. What am I doing wrong? What's the correct way to make classes from a submodule available in the parent module's namespace?</p>