Patchwork D2364: py3: use list comprehensions instead of filter where we need to eagerly filter

login
register
mail settings
Submitter phabricator
Date Feb. 21, 2018, 5:42 p.m.
Message ID <differential-rev-PHID-DREV-7nr3bxkmlyr7wmu56xds-req@phab.mercurial-scm.org>
Download mbox | patch
Permalink /patch/28196/
State Superseded
Headers show

Comments

phabricator - Feb. 21, 2018, 5:42 p.m.
durin42 created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  These two uses of filter() are then checked for truthiness, but on Python 3:
  
  >>> bool(filter(None, []))
  
  True
  
  So we need to stop depending on that. Fortunately it's easy to replace
  the filter with an equivalent list comprehension.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D2364

AFFECTED FILES
  mercurial/cmdutil.py
  mercurial/copies.py

CHANGE DETAILS




To: durin42, #hg-reviewers
Cc: mercurial-devel

Patch

diff --git a/mercurial/copies.py b/mercurial/copies.py
--- a/mercurial/copies.py
+++ b/mercurial/copies.py
@@ -685,8 +685,8 @@ 
     # the base and present in the source.
     # Presence in the base is important to exclude added files, presence in the
     # source is important to exclude removed files.
-    missingfiles = filter(lambda f: f not in m1 and f in base and f in c2,
-                          changedfiles)
+    filt = lambda f: f not in m1 and f in base and f in c2
+    missingfiles = [f for f in changedfiles if filt(f)]
 
     if missingfiles:
         basenametofilename = collections.defaultdict(list)
diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1831,7 +1831,7 @@ 
                 else:
                     self.revs.discard(value)
                     ctx = change(value)
-                    matches = filter(match, ctx.files())
+                    matches = [f for f in ctx.files() if match(f)]
                     if matches:
                         fncache[value] = matches
                         self.set.add(value)