title: Excluding modules when importing everything in __init__.py
body: <p><strong>Problem</strong></p>
  
  <p>Consider the following layout:</p>
  
  <pre><code>package/
      main.py
      math_helpers/
          mymath.py
          __init__.py
  </code></pre>
  
  <p><code>mymath.py</code> contains:</p>
  
  <pre><code>import math
  
  def foo():
      pass
  </code></pre>
  
  <p>In <code>main.py</code> I want to be able to use code from <code>mymath.py</code> like so:</p>
  
  <pre><code>import math_helpers
  math_helpers.foo()
  </code></pre>
  
  <p>In order to do so, <code>__init__.py</code> contains:</p>
  
  <pre><code>from .mymath import *
  </code></pre>
  
  <p>However, modules imported in <code>mymath.py</code> are now in the <code>math_helpers</code> namespace, e.g. <code>math_helpers.math</code> is accessible.</p>
  
  <hr>
  
  <p><strong>Current approach</strong></p>
  
  <p>I'm adding the following at the end of <code>mymath.py</code>.</p>
  
  <pre><code>import types
  __all__ = [name for name, thing in globals().items()
            if not (name.startswith('_') or isinstance(thing, types.ModuleType))]
  </code></pre>
  
  <p>This seems to work, but is it the correct approach?</p>