From 4da977010029bbe4d94e5c6ad8db10f62cab6276 Mon Sep 17 00:00:00 2001 From: Craig Rodrigues Date: Sat, 11 Mar 2017 13:03:23 -0800 Subject: Replace list(filter()) with list comprehension. --- QMTest/TestCommon.py | 2 +- src/engine/SCons/Action.py | 2 +- src/engine/SCons/Scanner/Dir.py | 2 +- src/engine/SCons/Script/Interactive.py | 2 +- src/engine/SCons/Script/Main.py | 2 +- src/engine/SCons/Tool/dvipdf.py | 2 +- src/engine/SCons/Tool/packaging/__init__.py | 4 ++-- src/test_aegistests.py | 2 +- test/Java/Java-1.4.py | 2 +- test/Java/Java-1.5.py | 2 +- test/Java/Java-1.6.py | 2 +- 11 files changed, 12 insertions(+), 12 deletions(-) diff --git a/QMTest/TestCommon.py b/QMTest/TestCommon.py index cd9e990..c1adc37 100644 --- a/QMTest/TestCommon.py +++ b/QMTest/TestCommon.py @@ -582,7 +582,7 @@ class TestCommon(TestCmd): """ files = [is_List(x) and os.path.join(*x) or x for x in files] existing, missing = separate_files(files) - writable = list(filter(is_writable, existing)) + writable = [file for file in existing if is_writable(file)] if missing: print("Missing files: `%s'" % "', `".join(missing)) if writable: diff --git a/src/engine/SCons/Action.py b/src/engine/SCons/Action.py index eb215fd..be70293 100644 --- a/src/engine/SCons/Action.py +++ b/src/engine/SCons/Action.py @@ -778,7 +778,7 @@ class CommandAction(_ActionAction): _ActionAction.__init__(self, **kw) if is_List(cmd): - if list(filter(is_List, cmd)): + if [c for c in cmd if is_List(c)]: raise TypeError("CommandAction should be given only " \ "a single command") self.cmd_list = cmd diff --git a/src/engine/SCons/Scanner/Dir.py b/src/engine/SCons/Scanner/Dir.py index cbfb6fb..3b33fe5 100644 --- a/src/engine/SCons/Scanner/Dir.py +++ b/src/engine/SCons/Scanner/Dir.py @@ -27,7 +27,7 @@ import SCons.Scanner def only_dirs(nodes): is_Dir = lambda n: isinstance(n.disambiguate(), SCons.Node.FS.Dir) - return list(filter(is_Dir, nodes)) + return [node for node in nodes if is_Dir(node)] def DirScanner(**kw): """Return a prototype Scanner instance for scanning diff --git a/src/engine/SCons/Script/Interactive.py b/src/engine/SCons/Script/Interactive.py index 3c3d23a..cf6e247 100644 --- a/src/engine/SCons/Script/Interactive.py +++ b/src/engine/SCons/Script/Interactive.py @@ -222,7 +222,7 @@ class SConsInteractiveCmd(cmd.Cmd): def get_unseen_children(node, parent, seen_nodes=seen_nodes): def is_unseen(node, seen_nodes=seen_nodes): return node not in seen_nodes - return list(filter(is_unseen, node.children(scan=1))) + return [child for child in node.children(scan=1) if is_unseen(child)] def add_to_seen_nodes(node, parent, seen_nodes=seen_nodes): seen_nodes[node] = 1 diff --git a/src/engine/SCons/Script/Main.py b/src/engine/SCons/Script/Main.py index b82b6a5..aea6bea 100644 --- a/src/engine/SCons/Script/Main.py +++ b/src/engine/SCons/Script/Main.py @@ -1168,7 +1168,7 @@ def _build_targets(fs, options, targets, target_top): # or not a file, so go ahead and keep it as a default # target and let the engine sort it out: return 1 - d = list(filter(check_dir, SCons.Script.DEFAULT_TARGETS)) + d = [tgt for tgt in SCons.Script.DEFAULT_TARGETS if check_dir(tgt)] SCons.Script.DEFAULT_TARGETS[:] = d target_top = None lookup_top = None diff --git a/src/engine/SCons/Tool/dvipdf.py b/src/engine/SCons/Tool/dvipdf.py index 374b9c5..f1e9513 100644 --- a/src/engine/SCons/Tool/dvipdf.py +++ b/src/engine/SCons/Tool/dvipdf.py @@ -87,7 +87,7 @@ def PDFEmitter(target, source, env): """ def strip_suffixes(n): return not SCons.Util.splitext(str(n))[1] in ['.aux', '.log'] - source = list(filter(strip_suffixes, source)) + source = [src for src in source if strip_suffixes(src)] return (target, source) def generate(env): diff --git a/src/engine/SCons/Tool/packaging/__init__.py b/src/engine/SCons/Tool/packaging/__init__.py index 1727938..8aa4787 100644 --- a/src/engine/SCons/Tool/packaging/__init__.py +++ b/src/engine/SCons/Tool/packaging/__init__.py @@ -233,7 +233,7 @@ def copy_attr(f1, f2): """ copyit = lambda x: not hasattr(f2, x) and x[:10] == 'PACKAGING_' if f1._tags: - pattrs = list(filter(copyit, f1._tags)) + pattrs = [tag for tag in f1._tags if copyit(tag)] for attr in pattrs: f2.Tag(attr, f1.GetTag(attr)) @@ -288,7 +288,7 @@ def stripinstallbuilder(target, source, env): (file.builder.name=="InstallBuilder" or\ file.builder.name=="InstallAsBuilder")) - if len(list(filter(has_no_install_location, source))): + if len([src for src in source if has_no_install_location(src)]): warn(Warning, "there are files to package which have no\ InstallBuilder attached, this might lead to irreproducible packages") diff --git a/src/test_aegistests.py b/src/test_aegistests.py index 67b0e3f..57adc1d 100644 --- a/src/test_aegistests.py +++ b/src/test_aegistests.py @@ -65,7 +65,7 @@ re3 = re.compile(r' test/.*\.py') def filename_is_a_test(x): return re1.search(x) or re2.search(x) or re3.search(x) -test_files = list(filter(filename_is_a_test, sources)) +test_files = [file for file in sources if filename_is_a_test(file)] if test_files: sys.stderr.write("Found the following files with test names not marked as Aegis tests:\n") diff --git a/test/Java/Java-1.4.py b/test/Java/Java-1.4.py index c1eb5e5..4076783 100644 --- a/test/Java/Java-1.4.py +++ b/test/Java/Java-1.4.py @@ -350,7 +350,7 @@ def classes_must_match(dir, expect): def classes_must_not_exist(dir, expect): global failed - present = list(filter(os.path.exists, expect)) + present = [path for path in expect if os.path.exists(path)] if present: sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) for c in present: diff --git a/test/Java/Java-1.5.py b/test/Java/Java-1.5.py index 0f93a00..6659a16 100644 --- a/test/Java/Java-1.5.py +++ b/test/Java/Java-1.5.py @@ -346,7 +346,7 @@ def classes_must_match(dir, expect): def classes_must_not_exist(dir, expect): global failed - present = list(filter(os.path.exists, expect)) + present = [path for path in expect if os.path.exists(path)] if present: sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) for c in present: diff --git a/test/Java/Java-1.6.py b/test/Java/Java-1.6.py index bd7a48f..be46919 100644 --- a/test/Java/Java-1.6.py +++ b/test/Java/Java-1.6.py @@ -346,7 +346,7 @@ def classes_must_match(dir, expect): def classes_must_not_exist(dir, expect): global failed - present = list(filter(os.path.exists, expect)) + present = [path for path in expect if os.path.exists(path)] if present: sys.stderr.write("Found the following unexpected class files in '%s' after cleaning:\n" % dir) for c in present: -- cgit v0.12