[master 1/1] Beware of Python 3's version of the map() built-in function

vpodzime installerbot-noreply at redhat.com
Mon May 11 12:50:07 UTC 2015


From: Vratislav Podzimek <vpodzime at redhat.com>

It not only returns an iterator in Python 3, it actually works in the lazy
evaluation fashion. So if its returned value is not iterated over, the passed
function is not called on the iterable's items. Let's use a for cycle in these
places to make the iteration and function calls explicit.
---
 blivet/devices/storage.py         | 3 ++-
 tests/devicelibs_test/edd_test.py | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/blivet/devices/storage.py b/blivet/devices/storage.py
index 052b397..0815d1e 100644
--- a/blivet/devices/storage.py
+++ b/blivet/devices/storage.py
@@ -719,7 +719,8 @@ def addHook(self, new=True):
             False that are normally performed as part of the device constructor.
         """
         if not new:
-            map(lambda p: p.addChild(), self.parents)
+            for p in self.parents:
+                p.addChild()
 
     def populateKSData(self, data):
         # the common pieces are basically the formatting
diff --git a/tests/devicelibs_test/edd_test.py b/tests/devicelibs_test/edd_test.py
index d7d729c..3a538b5 100644
--- a/tests/devicelibs_test/edd_test.py
+++ b/tests/devicelibs_test/edd_test.py
@@ -168,7 +168,8 @@ def sda_vda(self):
     def sda_vda_no_pcidev(self):
         self.sda_vda()
         entries = [e for e in self.fs.fs if e.startswith("/sys/devices/pci")]
-        map(self.fs.os_remove, entries)
+        for e in entries:
+            self.fs.os_remove(e)
         return self.fs
 
     def sda_vda_no_host_bus(self):


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


More information about the anaconda-patches mailing list