[Yum-devel] [PATCH] Change map(lambda ... => list comprehensions

James Antill james at and.org
Mon Oct 12 14:13:50 UTC 2009


---
 cli.py            |    4 ++--
 yum/__init__.py   |   13 ++++++++-----
 yum/depsolve.py   |    3 ++-
 yum/packages.py   |    4 ++--
 yum/rpmsack.py    |    2 +-
 yum/sqlitesack.py |    6 +++---
 yumcommands.py    |    2 +-
 7 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/cli.py b/cli.py
index 332be99..b6bff1c 100644
--- a/cli.py
+++ b/cli.py
@@ -535,7 +535,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         """ If install argument doesn't match with case, tell the user. """
         matches = self.doPackageLists(patterns=[arg], ignore_case=True)
         matches = matches.installed + matches.available
-        matches = set(map(lambda x: x.name, matches))
+        matches = set((x.name for x in matches))
         if matches:
             msg = self.fmtKeyValFill(_('  * Maybe you meant: '),
                                      ", ".join(matches))
@@ -565,7 +565,7 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
                 _('Package(s) %s%s%s available, but not installed.'),
                                     hibeg, arg, hiend)
             return
-        matches = set(map(lambda x: x.name, matches.installed))
+        matches = set((x.name for x in matches.installed))
         if always_output or matches:
             self.verbose_logger.log(yum.logginglevels.INFO_2,
                                     _('No package %s%s%s available.'),
diff --git a/yum/__init__.py b/yum/__init__.py
index 6af81b8..4d2cbd0 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -3042,7 +3042,7 @@ class YumBase(depsolve.Depsolve):
                             ver=nevra_dict['version'], rel=nevra_dict['release'])
                 if len(availpkgs) > 1:
                     availpkgs = self._compare_providers(availpkgs, requiringPo)
-                    availpkgs = map(lambda x: x[0], availpkgs)
+                    availpkgs = [x[0] for x in availpkgs]
 
        
         # for any thing specified
@@ -3917,7 +3917,8 @@ class YumBase(depsolve.Depsolve):
                             toremove.append(po)
                             numleft -= 1
                         
-        map(lambda x: self.tsInfo.addErase(x), toremove)
+        for po in toremove:
+            self.tsInfo.addErase(po)
 
     def processTransaction(self, callback=None,rpmTestDisplay=None, rpmDisplay=None):
         '''
@@ -3954,9 +3955,11 @@ class YumBase(depsolve.Depsolve):
     def _downloadPackages(self,callback):
         ''' Download the need packages in the Transaction '''
         # This can be overloaded by a subclass.    
-        dlpkgs = map(lambda x: x.po, filter(lambda txmbr:
-                                            txmbr.ts_state in ("i", "u"),
-                                            self.tsInfo.getMembers()))
+        dlpkgs = []
+        # FIXME: Use getMembersWithState()
+        for txmbr in self.tsInfo.getMembers():
+            if txmbr.ts_state in ("i", "u"):
+                dlpkgs.append(txmbr.po)
         # Check if there is something to do
         if len(dlpkgs) == 0:
             return None
diff --git a/yum/depsolve.py b/yum/depsolve.py
index 8bed47c..6b65624 100644
--- a/yum/depsolve.py
+++ b/yum/depsolve.py
@@ -591,7 +591,8 @@ class Depsolve(object):
             # before, they're not going to be installed anymore, so we
             # should mark them to be re-checked
             if upgraded.has_key(best.pkgtup):
-                map(lambda x: self.tsInfo.remove(x), upgraded[best.pkgtup])
+                for x in upgraded[best.pkgtup]:
+                    self.tsInfo.remove(x)
 
         checkdeps = 1
         
diff --git a/yum/packages.py b/yum/packages.py
index 7bbb61d..e5e18b6 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -1106,8 +1106,8 @@ class YumHeaderPackage(YumAvailablePackage):
 
             lst = hdr[getattr(rpm, 'RPMTAG_%sVERSION' % tag)]
             vers = map(rpmUtils.miscutils.stringToVersion, lst)
-            vers = map(lambda x: (misc.share_data(x[0]), misc.share_data(x[1]),
-                                  misc.share_data(x[2])), vers)
+            vers = [(misc.share_data(x[0]), misc.share_data(x[1]),
+                     misc.share_data(x[2])) for x in vers]
 
             prcotype = tag2prco[tag]
             self.prco[prcotype] = map(misc.share_data, zip(name,flag,vers))
diff --git a/yum/rpmsack.py b/yum/rpmsack.py
index 93e14ec..8ed82d6 100644
--- a/yum/rpmsack.py
+++ b/yum/rpmsack.py
@@ -400,7 +400,7 @@ class RPMDBPackageSack(PackageSackBase):
     def searchPrimaryFieldsMultipleStrings(self, fields, searchstrings,
                                            lowered=False):
         if not lowered:
-            searchstrings = map(lambda x: x.lower(), searchstrings)
+            searchstrings = [x.lower() for x in searchstrings]
         ret = []
         for hdr, idx in self._all_packages():
             n = self._find_search_fields(fields, searchstrings, hdr)
diff --git a/yum/sqlitesack.py b/yum/sqlitesack.py
index ce2988f..70d6a91 100644
--- a/yum/sqlitesack.py
+++ b/yum/sqlitesack.py
@@ -358,7 +358,7 @@ class YumAvailablePackageSqlite(YumAvailablePackage, PackageObject, RpmBase):
     def simpleFiles(self, ftype='file'):
         sql = "SELECT name as fname FROM files WHERE pkgKey = ? and type = ?"
         cur = self._sql_MD('primary', sql, (self.pkgKey, ftype))
-        return map(lambda x: x['fname'], cur)
+        return [x['fname'] for x in cur]
 
     def returnPrco(self, prcotype, printable=False):
         prcotype = _share_data(prcotype)
@@ -951,7 +951,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
                 if not file_glob:
                     return int(filename in files)
 
-                fns = map(lambda f: '%s/%s' % (sql_dirname, f), files)
+                fns = ['%s/%s' % (sql_dirname, f) for f in files]
                 for match in fns:
                     if name_re.match(match):
                         return 1
@@ -1680,7 +1680,7 @@ class YumSqlitePackageSack(yumRepo.YumPackageSack):
             self._arch_allowed = set(archlist)
         else:
             self._arch_allowed = self._arch_allowed.intersection(archlist)
-        sarchlist = map(lambda x: "'%s'" % x , archlist)
+        sarchlist = ["'%s'" % x  for x in archlist]
         arch_query = ",".join(sarchlist)
 
         for (rep, cache) in self.primarydb.items():
diff --git a/yumcommands.py b/yumcommands.py
index 1451a36..ff7af56 100644
--- a/yumcommands.py
+++ b/yumcommands.py
@@ -779,7 +779,7 @@ class RepoListCommand(YumCommand):
             extcmds = extcmds[1:]
         else:
             arg = 'enabled'
-        extcmds = map(lambda x: x.lower(), extcmds)
+        extcmds = [x.lower() for x in extcmds]
 
         verbose = base.verbose_logger.isEnabledFor(logginglevels.DEBUG_3)
         try:
-- 
1.6.2.5



More information about the Yum-devel mailing list