[diffoscope] 01/01: comparators: Tidy re_tests with list comprehensions and implicit "x, y" unpacking over indexing; lambda/filter is not idiomatic Python 3.

Chris Lamb chris at chris-lamb.co.uk
Fri Jan 27 21:41:28 CET 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 1e5d30b43ddfd8e787861211462c0a681406a692
Author: Chris Lamb <lamby at debian.org>
Date:   Sat Jan 28 09:39:45 2017 +1300

    comparators: Tidy re_tests with list comprehensions and implicit "x, y" unpacking over indexing; lambda/filter is not idiomatic Python 3.
---
 diffoscope/comparators/utils/specialize.py | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/diffoscope/comparators/utils/specialize.py b/diffoscope/comparators/utils/specialize.py
index 7a3c3e9..75c8585 100644
--- a/diffoscope/comparators/utils/specialize.py
+++ b/diffoscope/comparators/utils/specialize.py
@@ -38,11 +38,14 @@ def specialize(file):
             with profile('recognizes', file):
                 flag = cls.recognizes(file)
         else:
-            re_tests = [(cls.RE_FILE_TYPE, file.magic_file_type),
-                        (cls.RE_FILE_EXTENSION, file.name)]
-            re_tests = list(filter(lambda pair: pair[0], re_tests))
-            if re_tests: # if neither are defined, it's *not* a match
-                flag = all(bool(pair[0].search(pair[1])) for pair in re_tests)
+            re_tests = [(x, y) for x, y in (
+                (cls.RE_FILE_TYPE, file.magic_file_type),
+                (cls.RE_FILE_EXTENSION, file.name),
+            ) if x]
+
+            # If neither are defined, it's *not* a match.
+            if re_tests:
+                flag = all(x.search(y) for x, y in re_tests)
 
         if not flag:
             continue

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list