[PATCH 3/3] Do not create lambda over and over in a cycle

Vratislav Podzimek vpodzime at redhat.com
Fri Jan 23 08:37:48 UTC 2015


On Thu, 2015-01-22 at 09:40 -0500, Anne Mulhern wrote:
> 
> 
> 
> ----- Original Message -----
> > From: "Vratislav Podzimek" <vpodzime at redhat.com>
> > To: anaconda-patches at lists.fedorahosted.org
> > Sent: Wednesday, January 21, 2015 5:50:36 AM
> > Subject: [PATCH 3/3] Do not create lambda over and over in a cycle
> > 
> > Let's just define and create it once and use it over and over.
> > 
> > Signed-off-by: Vratislav Podzimek <vpodzime at redhat.com>
> > ---
> >  scripts/makebumpver | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > diff --git a/scripts/makebumpver b/scripts/makebumpver
> > index 57f549f..07ce065 100755
> > --- a/scripts/makebumpver
> > +++ b/scripts/makebumpver
> > @@ -240,8 +240,9 @@ class MakeBumpVer:
> >                         proc[0].strip('\n').split('\n'))
> >  
> >          if self.ignore and self.ignore != '':
> > +            startswith_commit = lambda x: not x.startswith(commit)
> >              for commit in self.ignore.split(','):
> > -                lines = filter(lambda x: not x.startswith(commit), lines)
> > +                lines = filter(startswith_commit, lines)
> >  
> >          rpm_log = []
> >          bad_bump = False
> > --
> > 2.1.0
> > 
> > _______________________________________________
> > anaconda-patches mailing list
> > anaconda-patches at lists.fedorahosted.org
> > https://lists.fedorahosted.org/mailman/listinfo/anaconda-patches
> > 
> 
> List comprehension would be that much prettier.
> 
> lines = [l for l in lines if not x.startswith(commit)]
> 
> or even,
> 
> commits = self.ignore.split(',')
> lines = [l for l in lines if not any(l.startswith(c) for c in commits)]
> 
> which has advantage of not recomputing new list for every element in commit.
Agreed, but I'd still rather have two separate commits like:
* make pylint shut up
* make our code prettier

so unless somebody strongly disagrees, I'd like to push my original
patch and then add your suggested change as a follow-up commit.

-- 
Vratislav Podzimek

Anaconda Rider | Red Hat, Inc. | Brno - Czech Republic



More information about the anaconda-patches mailing list