D2364: py3: use list comprehensions instead of filter where we need to eagerly filter
durin42 (Augie Fackler)
phabricator at mercurial-scm.org
Wed Feb 21 17:42:10 UTC 2018
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
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)
To: durin42, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list