From 1c29f9b32f2abfe5b52a325b8c0a70df12f6bbf1 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Mon, 17 Jul 2017 10:55:19 -0700 Subject: crypto: simplify check_uid_validity This splits the loop into a closure and a call to any, which makes it a little bit easier to read and understand. --- alot/crypto.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'alot/crypto.py') diff --git a/alot/crypto.py b/alot/crypto.py index 7d62bb8a..c73d792c 100644 --- a/alot/crypto.py +++ b/alot/crypto.py @@ -265,9 +265,10 @@ def check_uid_validity(key, email): :returns: whether the key can be assumed to belong to the given email :rtype: bool """ - for key_uid in key.uids: - if email == key_uid.email and not key_uid.revoked and \ - not key_uid.invalid and \ - key_uid.validity >= gpg.constants.validity.FULL: - return True - return False + def check(key_uid): + return (email == key_uid.email and + not key_uid.revoked and + not key_uid.invalid and + key_uid.validity >= gpg.constants.validity.FULL) + + return any(check(u) for u in key.uids) -- cgit v1.2.3