[master 1/15] Replace __import__ call with importlib.import_module

vpodzime installerbot-noreply at redhat.com
Thu Apr 2 14:15:06 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

As __import__'s docstring says:
"Import a module. Because this function is meant for use by the Python
interpreter and not for general use it is better to use
importlib.import_module() to programmatically import a module."

Also __import__ is a bit different in Python 2 and Python 3.
---
 blivet/formats/__init__.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/blivet/formats/__init__.py b/blivet/formats/__init__.py
index 4bd9105..08ad8d1 100644
--- a/blivet/formats/__init__.py
+++ b/blivet/formats/__init__.py
@@ -22,6 +22,7 @@
 #
 
 import os
+import importlib
 from gi.repository import BlockDev as blockdev
 from gi.repository import GLib
 
@@ -106,7 +107,7 @@ def collect_device_format_classes():
         (mod_name, ext) = os.path.splitext(module_file)
         if ext == ".py" and mod_name != myfile_name:
             try:
-                globals()[mod_name] = __import__(mod_name, globals(), locals(), [], -1)
+                globals()[mod_name] = importlib.import_module("."+mod_name, package=__package__)
             except ImportError:
                 log.error("import of device format module '%s' failed", mod_name)
                 from traceback import format_exc


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


More information about the anaconda-patches mailing list