Keeping imported modules out of python package namespaces
<p>I've noticed sometimes if you call <code>dir()</code> on a package/module, you'll see other modules in the namespace that were imported as part of the implementation and aren't meant for you to use. For instance, if I install the fish package from PyPI and import it, I see <code>fish.sys</code>, which just refers to the built-in <code>sys</code> module.</p>

<p>My question is whether that's sane and what to do about it if it's not.</p>

<p>I don't think the <code>__all__</code> variable is too relevant, since that <em>only</em> affects the behavior of <code>from X import *</code>. The options I see are:</p>

<ul>
<li>structure your packages better, and at least push the namespace clutter down into submodules</li>
<li>use <code>import X as _X</code> in your package to distinguish implementation details from your package API</li>
<li>import things from inside your functions (<em>blegh</em>)</li>
</ul>
