From 22fe0a87e78df902d4f6d3bb9b615e57b1062839 2015-04-28 23:31:09 From: Min RK Date: 2015-04-28 23:31:09 Subject: [PATCH] ensure `__all__` and `__dir__` are defined on shims require from `from shim import *` to work properly --- diff --git a/IPython/utils/shimmodule.py b/IPython/utils/shimmodule.py index d05879d..3c5be33 100644 --- a/IPython/utils/shimmodule.py +++ b/IPython/utils/shimmodule.py @@ -68,6 +68,18 @@ class ShimModule(types.ModuleType): def __spec__(self): """Don't produce __spec__ until requested""" return __import__(self._mirror).__spec__ + + def __dir__(self): + return dir(__import__(self._mirror)) + + @property + def __all__(self): + """Ensure __all__ is always defined""" + mod = __import__(self._mirror) + try: + return mod.__all__ + except AttributeError: + return [name for name in dir(mod) if not name.startswith('_')] def __getattr__(self, key): # Use the equivalent of import_item(name), see below