title: Weird namespace pollution when importing submodule in a package's __init__.py
body: <p>main.py:</p>
  
  <pre><code>    import package
  </code></pre>
  
  <p>package/__init__.py:</p>
  
  <pre><code>    # use function to split local and global namespace
      def do_import():
          print globals().keys()
          print locals().keys()
  
          import foo as mod
  
          print locals().keys()
          print globals().keys()
  
      do_import()
  </code></pre>
  
  <p>package/foo.py:</p>
  
  <pre><code>    print 'Hello from foo'
  </code></pre>
  
  <p>Execute main.py will output like this:</p>
  
  <pre><code>['__builtins__', '__file__', '__package__', '__path__', '__name__', 'do_import', '__doc__']
  []
  Hello from foo
  ['mod']
  ['__builtins__', '__file__', '__package__', '__path__', '__name__', 'foo', 'do_import', '__doc__']
  </code></pre>
  
  <p>The <code>import</code> in <code>__init__.py</code> didn't work as expected.
  Notice that the global namespace has a 'foo' which should bind to local 'mod' only</p>
  
  <p>Even a
  <code>exec "import foo as mod" in {'__name__': __name__, '__path__': __path__}</code>
  cannot stop global namespace from being modified</p>
  
  <p>How could this happen?</p>