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

Anne Mulhern amulhern at redhat.com
Thu Jan 29 12:40:35 UTC 2015





----- Original Message -----
> From: "Vratislav Podzimek" <vpodzime at redhat.com>
> To: "anaconda patch review" <anaconda-patches at lists.fedorahosted.org>
> Sent: Thursday, January 29, 2015 3:20:39 AM
> Subject: Re: [PATCH 3/9] Make filter() usage Python 3 compatible (#1014220)
> 
> On Wed, 2015-01-28 at 16:49 -0500, Anne Mulhern wrote:
> > 
> > 
> > 
> > ----- 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").
> I don't think it's unnecessary. kwargs.get("groups") returns None if
> "groups" doesn't exist in kwargs. And 'map(something, None)' raises an
> exception. The 'if grp' check is outside of the map() call.
> 

Whoops!

Thanks for catching that.

- mulhern

> --
> Vratislav Podzimek
> 
> Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic
> 
> _______________________________________________
> anaconda-patches mailing list
> anaconda-patches at lists.fedorahosted.org
> https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> 


More information about the anaconda-patches mailing list