Change filter with lambda to list comprehension

It is more readable and returns a list therefore it is compatible both
with Python 2 and 3.

Signed-off-by: Łukasz Żarnowiecki <dolohow@outlook.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
This commit is contained in:
Łukasz Żarnowiecki 2016-05-08 16:55:13 +02:00 committed by Nicolas Sebrecht
parent 068ac7c410
commit 19c43308b9
5 changed files with 11 additions and 17 deletions

View File

@ -438,8 +438,7 @@ def syncfolder(account, remotefolder, quick):
# sync to messages with UIDs >= min_uid from this list.
#
# local messagelist might contain new messages (with uid's < 0).
positive_uids = filter(
lambda uid: uid > 0, localfolder.getmessageuidlist())
positive_uids = [uid for uid in localfolder.getmessageuidlist() if uid > 0]
if len(positive_uids) > 0:
remotefolder.cachemessagelist(min_uid=min(positive_uids))
else:
@ -482,8 +481,7 @@ def syncfolder(account, remotefolder, quick):
# messagelist.keys() instead of getuidmessagelist() because in
# the UID mapped case we want the actual local UIDs, not their
# remote counterparts
positive_uids = filter(
lambda uid: uid > 0, partial.messagelist.keys())
positive_uids = [uid for uid in list(partial.messagelist.keys()) if uid > 0]
if len(positive_uids) > 0:
min_uid = min(positive_uids)
else:

View File

@ -858,8 +858,7 @@ class BaseFolder(object):
threads = []
copylist = filter(lambda uid: not statusfolder.uidexists(uid),
self.getmessageuidlist())
copylist = [uid for uid in self.getmessageuidlist() if not statusfolder.uidexists(uid)]
num_to_copy = len(copylist)
if num_to_copy and self.repository.account.dryrun:
self.ui.info("[DRYRUN] Copy {0} messages from {1}[{2}] to {3}".format(
@ -909,10 +908,10 @@ class BaseFolder(object):
# The list of messages to delete. If sync of deletions is disabled we
# still remove stale entries from statusfolder (neither in local nor
# remote).
deletelist = filter(
lambda uid: uid >= 0 and not self.uidexists(uid)
and (self._sync_deletes or not dstfolder.uidexists(uid)),
statusfolder.getmessageuidlist())
deletelist = [uid for uid in statusfolder.getmessageuidlist()
if uid >= 0 and
not self.uidexists(uid) and
(self._sync_deletes or not dstfolder.uidexists(uid))]
if len(deletelist):
# Delete in statusfolder first to play safe. In case of abort, we
@ -921,7 +920,7 @@ class BaseFolder(object):
# user, or not being tracked (e.g. because of maxage).
statusfolder.deletemessages(deletelist)
# Filter out untracked messages
deletelist = filter(lambda uid: dstfolder.uidexists(uid), deletelist)
deletelist = [uid for uid in deletelist if dstfolder.uidexists(uid)]
if len(deletelist):
self.ui.deletingmessages(deletelist, [dstfolder])
if self.repository.account.dryrun:

View File

@ -204,7 +204,7 @@ class MaildirFolder(BaseFolder):
retval[uid]['filename'] = filepath
if min_date != None:
# Re-include messages with high enough uid's.
positive_uids = filter(lambda uid: uid > 0, retval)
positive_uids = [uid for uid in retval if uid > 0]
if positive_uids:
min_uid = min(positive_uids)
for uid in date_excludees.keys():

View File

@ -433,8 +433,7 @@ class IMAPServer:
if not tried_to_authn:
methods = ", ".join(map(
lambda x: x[5:], filter(lambda x: x[0:5] == "AUTH=",
imapobj.capabilities)
lambda x: x[5:], [x for x in imapobj.capabilities if x[0:5] == "AUTH="]
))
raise OfflineImapError(u"Repository %s: no supported "
"authentication mechanisms found; configured %s, "

View File

@ -131,9 +131,7 @@ class OLITestLib():
else:
sections = [r for r in config.sections() \
if r.startswith('Repository')]
sections = filter(lambda s: \
config.get(s, 'Type').lower() == 'imap',
sections)
sections = [s for s in sections if config.get(s, 'Type').lower() == 'imap']
for sec in sections:
# Connect to each IMAP repo and delete all folders
# matching the folderfilter setting. We only allow basic