This makes the 'TAB-TAB' completion in ipython and dir() calls work as if the lazy-imported object was imported in a normal way.
From: Vratislav Podzimek vpodzime@redhat.com
This makes the 'TAB-TAB' completion in ipython and dir() calls work as if the lazy-imported object was imported in a normal way. --- blivet/__init__.py | 6 ++++++ 1 file changed, 6 insertions(+)
diff --git a/blivet/__init__.py b/blivet/__init__.py index 75a682e..ca06ec4 100644 --- a/blivet/__init__.py +++ b/blivet/__init__.py @@ -167,6 +167,12 @@ def __getattr__(self, attr): sys.modules["%s.%s" % (__package__, self._name)] = val return getattr(val, attr)
+ def __dir__(self): + mod = importlib.import_module(__package__+"."+self._real_mod) + val = getattr(mod, self._name) + sys.modules["%s.%s" % (__package__, self._name)] = val + return dir(val) + # this way things like 'from blivet import Blivet' work without an overhead of # importing of everything the Blivet class needs whenever anything from the # 'blivet' package is imported (e.g. the 'arch' module)
Added label: ACK.
Looks good to me, ACK!
Looks good to jenkins, too. Cool!
anaconda-patches@lists.fedorahosted.org