[PATCH 3/9] Make filter() usage Python 3 compatible (#1014220)

Anne Mulhern amulhern at redhat.com
Wed Jan 28 21:49:54 UTC 2015





----- Original Message -----
> From: "Martin Kolman" <mkolman at redhat.com>
> To: anaconda-patches at lists.fedorahosted.org
> Sent: Wednesday, January 28, 2015 12:43:17 PM
> Subject: [PATCH 3/9] Make filter() usage Python 3 compatible (#1014220)
> 
> The filter() function no longer returns a list but an interator in Python 3,

^interator^iterator

> so replace all usage of filter() that expect a list by list comprehension.
> 
> Signed-off-by: Martin Kolman <mkolman at redhat.com>
> ---
>  pyanaconda/bootloader.py            | 4 ++--
>  pyanaconda/kickstart.py             | 4 ++--
>  pyanaconda/ui/gui/spokes/storage.py | 3 +--
>  pyanaconda/users.py                 | 5 ++---
>  4 files changed, 7 insertions(+), 9 deletions(-)
> 
> diff --git a/pyanaconda/bootloader.py b/pyanaconda/bootloader.py
> index b017265..444a3f0 100644
> --- a/pyanaconda/bootloader.py
> +++ b/pyanaconda/bootloader.py
> @@ -1985,7 +1985,7 @@ class IPSeriesYaboot(Yaboot):
>  
>          # Place the disk containing the PReP partition first.
>          # Remove all other occurances of it.
> -        boot_list = [boot_disk] + filter(lambda x: x != boot_disk,
> boot_list)
> +        boot_list = [boot_disk] + [x for x in boot_list if x != boot_disk]
>  
>          log.debug("updatePowerPCBootList: updated boot_list = %s",
>          boot_list)
>  
> @@ -2046,7 +2046,7 @@ class IPSeriesGRUB2(GRUB2):
>  
>          # Place the disk containing the PReP partition first.
>          # Remove all other occurances of it.
> -        boot_list = [boot_disk] + filter(lambda x: x != boot_disk,
> boot_list)
> +        boot_list = [boot_disk] + [x for x in boot_list if x != boot_disk]
>  
>          update_value = "boot-device=%s" % " ".join(boot_list)
>  
> diff --git a/pyanaconda/kickstart.py b/pyanaconda/kickstart.py
> index 5701eff..ec1d33c 100644
> --- a/pyanaconda/kickstart.py
> +++ b/pyanaconda/kickstart.py
> @@ -1972,7 +1972,7 @@ def appendPostScripts(ksdata):
>      ksparser.readKickstartFromString(scripts, reset=False)
>  
>  def runPostScripts(scripts):
> -    postScripts = filter (lambda s: s.type == KS_SCRIPT_POST, scripts)
> +    postScripts = [s for s in scripts if s.type == KS_SCRIPT_POST]
>  
>      if len(postScripts) == 0:
>          return
> @@ -1987,7 +1987,7 @@ def runPostScripts(scripts):
>      log.info("All kickstart %%post script(s) have been run")
>  
>  def runPreScripts(scripts):
> -    preScripts = filter (lambda s: s.type == KS_SCRIPT_PRE, scripts)
> +    preScripts = [s for s in scripts if s.type == KS_SCRIPT_PRE]
>  
>      if len(preScripts) == 0:
>          return
> diff --git a/pyanaconda/ui/gui/spokes/storage.py
> b/pyanaconda/ui/gui/spokes/storage.py
> index 88f1a8a..9144f6a 100644
> --- a/pyanaconda/ui/gui/spokes/storage.py
> +++ b/pyanaconda/ui/gui/spokes/storage.py
> @@ -398,8 +398,7 @@ class StorageSpoke(NormalSpoke, StorageChecker):
>  
>      @property
>      def advancedOverviews(self):
> -        return filter(lambda child: isinstance(child,
> AnacondaWidgets.DiskOverview),
> -                      self.specialized_disks_box.get_children())
> +        return [child for child in self.specialized_disks_box.get_children()
> if isinstance(child, AnacondaWidgets.DiskOverview)]
>  
>      def _on_disk_clicked(self, overview, event):
>          # This handler only runs for these two kinds of events, and only for
> diff --git a/pyanaconda/users.py b/pyanaconda/users.py
> index be1d9cc..cedf2db 100644
> --- a/pyanaconda/users.py
> +++ b/pyanaconda/users.py
> @@ -301,10 +301,9 @@ class Users:
>              if kwargs.get("gid", -1) >= 0:
>                  groupEnt.set(libuser.GIDNUMBER, kwargs["gid"])
>  
> -            grpLst = filter(lambda grp: grp,
> -                            map(self.admin.lookupGroupByName,
> kwargs.get("groups", [])))
> +            grpLst = [grp for grp in map(self.admin.lookupGroupByName,
> kwargs.get("groups", [])) if grp]

The empty list is unnecessary. Since you're touching this line anyway,
you could just drop in favor of kwargs.get("groups").

>              userEnt.set(libuser.GIDNUMBER,
>              [groupEnt.get(libuser.GIDNUMBER)[0]] +
> -                        map(lambda grp: grp.get(libuser.GIDNUMBER)[0],
> grpLst))
> +                        [grp.get(libuser.GIDNUMBER)[0] for grp in grpLst])
>  
>              homedir = kwargs.get("homedir", None)
>              if not homedir:
> --
> 2.1.0
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 

Some inline comments, otherwise ack.

- mulhern


More information about the anaconda-patches mailing list