[master 1/1] Implement the __dir__ method of the LazyImportObject class

vpodzime installerbot-noreply at redhat.com
Fri Mar 20 11:59:22 UTC 2015


From: Vratislav Podzimek <vpodzime at 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)


-- 
To view this commit on github, visit https://github.com/rhinstaller/blivet/commit/0cf27fbdbc668a5075317955e1937a2b5d929ef9


More information about the anaconda-patches mailing list