Skip to content

Commit

Permalink
Remove None-entries of namespace packages on _localimport.__enter__, C…
Browse files Browse the repository at this point in the history
…lose #11
  • Loading branch information
NiklasRosenstein committed Nov 10, 2015
1 parent c936e9b commit 842d2ae
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -25,6 +25,7 @@ assert 'some_package' not in sys.modules

__v1.4.9__

* Fix #11, remove `None`-entries of namespace packages in `sys.modules`
* `_localimport._extend_path()` is is now less tolerant about extending
the namespace path and only does so when a `__init__.{py,pyc,pyo}` file
exists in the parsed directory
Expand Down
10 changes: 8 additions & 2 deletions localimport.py
Expand Up @@ -19,7 +19,7 @@
# THE SOFTWARE.

__author__ = 'Niklas Rosenstein <rosensteinniklas@gmail.com>'
__version__ = '1.4.8'
__version__ = '1.4.9'

import glob, os, pkgutil, sys, traceback, zipfile
class _localimport(object):
Expand Down Expand Up @@ -119,7 +119,13 @@ def __enter__(self):

# Update the __path__ of all namespace modules.
for key, mod in sys.modules.items():
if hasattr(mod, '__path__'):
if mod is None:
# Relative imports could have lead to None-entries in
# sys.modules. Get rid of them so they can be re-evaluated.
prefix = key.rpartition('.')[0]
if hasattr(sys.modules.get(prefix), '__path__'):
del sys.modules[key]
elif hasattr(mod, '__path__'):
self.state['nspaths'][key] = mod.__path__[:]
mod.__path__ = pkgutil.extend_path(mod.__path__, mod.__name__)

Expand Down

0 comments on commit 842d2ae

Please sign in to comment.