From 42fbdd74fd8de04976c9d53ab0bf36fd26518c69 Mon Sep 17 00:00:00 2001 From: Jeremy Andrews Date: Wed, 4 Mar 2026 13:12:43 -0600 Subject: [PATCH] Issue #2974 - Part 3: Adapt filter. 2to3 . --fix filter -wpn Py2 filter was a list, now filter is an iterator. This lets you have the old behavior. Mechanical. Ref: https://www.artima.com/weblogs/viewpost.jsp?thread=208549 --- accessible/xpcom/AccEventGen.py | 12 ++++++------ build/pymake/pymake/data.py | 5 ++--- build/pymake/pymake/globrelative.py | 2 +- dom/bindings/Codegen.py | 18 +++++++++--------- dom/bindings/Configuration.py | 11 +++++------ .../renderer/gen_angle_format_table.py | 2 +- gfx/harfbuzz/src/gen-tag-table.py | 2 +- gfx/skia/generate_mozbuild.py | 2 +- js/src/devtools/automation/autospider.py | 2 +- .../rootAnalysis/t/suppression/test.py | 6 +++--- js/src/devtools/rootAnalysis/t/testlib.py | 4 ++-- js/src/vm/make_unicode.py | 4 ++-- layout/style/GenerateCSSPropsGenerated.py | 2 +- media/libaom/generate_sources_mozbuild.py | 12 ++++++------ .../build/android/pylib/json_perf_parser.py | 2 +- media/webrtc/trunk/build/android/run_tests.py | 6 ++---- .../tools/gyp/pylib/gyp/generator/make.py | 8 ++++---- .../tools/gyp/pylib/gyp/generator/ninja.py | 10 +++++----- .../trunk/tools/gyp/pylib/gyp/mac_tool.py | 2 +- .../tools/gyp/pylib/gyp/msvs_emulation.py | 15 +++++++-------- .../trunk/tools/gyp/pylib/gyp/ninja_syntax.py | 2 +- .../webrtc/trunk/tools/gyp/test/lib/TestCmd.py | 2 +- .../trunk/tools/gyp/test/lib/TestCommon.py | 8 ++++---- .../gyp/test/mac/gyptest-strip-default.py | 2 +- python/eme/gen-eme-voucher.py | 10 +++++----- python/mach/mach/main.py | 2 +- python/macholib/macholib/MachOStandalone.py | 2 +- .../mozbuild/mozbuild/backend/recursivemake.py | 4 ++-- python/py/py/_code/code.py | 2 +- python/py/py/_log/log.py | 2 +- python/py/py/_path/local.py | 2 +- python/py/py/_path/svnurl.py | 2 +- python/py/py/_path/svnwc.py | 6 +++--- python/pystache/setup.py | 2 +- python/pytest/_pytest/_code/code.py | 2 +- python/pytest/_pytest/pytester.py | 4 ++-- python/pytest/_pytest/python.py | 2 +- .../requests/packages/urllib3/util/retry.py | 2 +- taskcluster/taskgraph/target_tasks.py | 6 +++--- taskcluster/taskgraph/try_option_syntax.py | 4 ++-- .../mod_pywebsocket/handshake/hybi.py | 9 +++------ testing/mochitest/runtests.py | 2 +- .../mozdevice/mozdevice/devicemanager.py | 2 +- .../mozdevice/mozdevice/devicemanagerSUT.py | 4 ++-- testing/mozbase/mozhttpd/mozhttpd/mozhttpd.py | 6 +++--- .../mozharness/external_tools/detect_repo.py | 2 +- testing/mozharness/scripts/gaia_unit.py | 2 +- testing/talos/talos/scripts/report.py | 4 ++-- testing/talos/talos/xtalos/etlparser.py | 5 ++--- 49 files changed, 111 insertions(+), 120 deletions(-) diff --git a/accessible/xpcom/AccEventGen.py b/accessible/xpcom/AccEventGen.py index 6af54c34db..ce79cb1ae9 100755 --- a/accessible/xpcom/AccEventGen.py +++ b/accessible/xpcom/AccEventGen.py @@ -64,7 +64,7 @@ def print_header_file(fd, conf, incdirs): for e in conf.simple_events: idl, idl_path = loadEventIDL(p, incdirs, e) idl_paths.add(idl_path) - for iface in filter(lambda p: p.kind == "interface", idl.productions): + for iface in [p for p in idl.productions if p.kind == "interface"]: classname = ("xpcAcc%s" % e) baseinterfaces = interfaces(iface) @@ -83,7 +83,7 @@ def print_header_file(fd, conf, incdirs): fd.write(" NS_DECL_CYCLE_COLLECTING_ISUPPORTS\n") fd.write(" NS_DECL_CYCLE_COLLECTION_CLASS(%s)\n" % (classname)) - for iface in filter(lambda i: i.name != "nsISupports", baseinterfaces): + for iface in [i for i in baseinterfaces if i.name != "nsISupports"]: fd.write(" NS_DECL_%s\n" % iface.name.upper()) fd.write("\nprivate:\n") @@ -97,12 +97,12 @@ def print_header_file(fd, conf, incdirs): return idl_paths def interfaceAttributeTypes(idl): - ifaces = filter(lambda p: p.kind == "interface", idl.productions) + ifaces = [p for p in idl.productions if p.kind == "interface"] attributes = [] for i in ifaces: ifaceAttributes = allAttributes(i) attributes.extend(ifaceAttributes) - ifaceAttrs = filter(lambda a: a.realtype.nativeType("in").endswith("*"), attributes) + ifaceAttrs = [a for a in attributes if a.realtype.nativeType("in").endswith("*")] return map(lambda a: a.realtype.nativeType("in").strip(" *"), ifaceAttrs) def print_cpp(idl, fd, conf, eventname): @@ -186,7 +186,7 @@ def interfaces(iface): def allAttributes(iface): attributes = [] for i in interfaces(iface): - attrs = filter(lambda m: isinstance(m, xpidl.Attribute), i.members) + attrs = [m for m in i.members if isinstance(m, xpidl.Attribute)] attributes.extend(attrs) return attributes @@ -194,7 +194,7 @@ def allAttributes(iface): def write_cpp(eventname, iface, fd): classname = "xpcAcc%s" % eventname attributes = allAttributes(iface) - ccattributes = filter(lambda m: m.realtype.nativeType('in').endswith('*'), attributes) + ccattributes = [m for m in attributes if m.realtype.nativeType('in').endswith('*')] fd.write("NS_IMPL_CYCLE_COLLECTION(%s" % classname) for c in ccattributes: fd.write(", m%s" % firstCap(c.name)) diff --git a/build/pymake/pymake/data.py b/build/pymake/pymake/data.py index d0b5804e70..540147cf31 100644 --- a/build/pymake/pymake/data.py +++ b/build/pymake/pymake/data.py @@ -1750,9 +1750,8 @@ class Makefile(object): if value is None: self._vpath = [] else: - self._vpath = filter(lambda e: e != '', - re.split('[%s\s]+' % os.pathsep, - value.resolvestr(self, self.variables, ['VPATH']))) + self._vpath = [e for e in re.split('[%s\s]+' % os.pathsep, + value.resolvestr(self, self.variables, ['VPATH'])) if e != ''] targets = list(self._targets.itervalues()) for t in targets: diff --git a/build/pymake/pymake/globrelative.py b/build/pymake/pymake/globrelative.py index 37ca28e068..64311ae428 100644 --- a/build/pymake/pymake/globrelative.py +++ b/build/pymake/pymake/globrelative.py @@ -62,7 +62,7 @@ def globpattern(dir, pattern): if not leaf.startswith('.')] leaves = fnmatch.filter(leaves, pattern) - leaves = filter(lambda l: os.path.exists(util.normaljoin(dir, l)), leaves) + leaves = [l for l in leaves if os.path.exists(util.normaljoin(dir, l))] leaves.sort() return leaves diff --git a/dom/bindings/Codegen.py b/dom/bindings/Codegen.py index 17e5502504..88c9bb6a9e 100644 --- a/dom/bindings/Codegen.py +++ b/dom/bindings/Codegen.py @@ -4999,7 +4999,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, memberTypes = type.flatMemberTypes names = [] - interfaceMemberTypes = filter(lambda t: t.isNonCallbackInterface(), memberTypes) + interfaceMemberTypes = [t for t in memberTypes if t.isNonCallbackInterface()] if len(interfaceMemberTypes) > 0: interfaceObject = [] for memberType in interfaceMemberTypes: @@ -5013,7 +5013,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, else: interfaceObject = None - sequenceObjectMemberTypes = filter(lambda t: t.isSequence(), memberTypes) + sequenceObjectMemberTypes = [t for t in memberTypes if t.isSequence()] if len(sequenceObjectMemberTypes) > 0: assert len(sequenceObjectMemberTypes) == 1 name = getUnionMemberName(sequenceObjectMemberTypes[0]) @@ -5024,7 +5024,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, else: sequenceObject = None - dateObjectMemberTypes = filter(lambda t: t.isDate(), memberTypes) + dateObjectMemberTypes = [t for t in memberTypes if t.isDate()] if len(dateObjectMemberTypes) > 0: assert len(dateObjectMemberTypes) == 1 memberType = dateObjectMemberTypes[0] @@ -5036,7 +5036,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, else: dateObject = None - callbackMemberTypes = filter(lambda t: t.isCallback() or t.isCallbackInterface(), memberTypes) + callbackMemberTypes = [t for t in memberTypes if t.isCallback() or t.isCallbackInterface()] if len(callbackMemberTypes) > 0: assert len(callbackMemberTypes) == 1 memberType = callbackMemberTypes[0] @@ -5048,7 +5048,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, else: callbackObject = None - dictionaryMemberTypes = filter(lambda t: t.isDictionary(), memberTypes) + dictionaryMemberTypes = [t for t in memberTypes if t.isDictionary()] if len(dictionaryMemberTypes) > 0: assert len(dictionaryMemberTypes) == 1 name = getUnionMemberName(dictionaryMemberTypes[0]) @@ -5059,7 +5059,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, else: setDictionary = None - recordMemberTypes = filter(lambda t: t.isRecord(), memberTypes) + recordMemberTypes = [t for t in memberTypes if t.isRecord()] if len(recordMemberTypes) > 0: assert len(recordMemberTypes) == 1 name = getUnionMemberName(recordMemberTypes[0]) @@ -5070,7 +5070,7 @@ def getJSToNativeConversionInfo(type, descriptorProvider, failureCode=None, else: recordObject = None - objectMemberTypes = filter(lambda t: t.isObject(), memberTypes) + objectMemberTypes = [t for t in memberTypes if t.isObject()] if len(objectMemberTypes) > 0: assert len(objectMemberTypes) == 1 # Very important to NOT construct a temporary Rooted here, since the @@ -8255,7 +8255,7 @@ class CGMethodCall(CGThing): # a string overload, then boolean and numeric are conditional, and # if not then boolean is conditional if we have a numeric overload. def findUniqueSignature(filterLambda): - sigs = filter(filterLambda, possibleSignatures) + sigs = list(filter(filterLambda, possibleSignatures)) assert len(sigs) < 2 if len(sigs) > 0: return sigs[0] @@ -17087,7 +17087,7 @@ class CGEventMethod(CGNativeMember): # -3 on the left to ignore the type, bubbles, and cancelable parameters # -1 on the right to ignore the .trusted property which bleeds through # here because it is [Unforgeable]. - len(signature[1]) - 3 == len(filter(lambda x: x.isAttr(), iface.members)) - 1): + len(signature[1]) - 3 == len([x for x in iface.members if x.isAttr()]) - 1): allowed = True self.isInit = True diff --git a/dom/bindings/Configuration.py b/dom/bindings/Configuration.py index 2669e3e4cd..69dbc42a31 100644 --- a/dom/bindings/Configuration.py +++ b/dom/bindings/Configuration.py @@ -149,8 +149,7 @@ class Configuration(DescriptorProvider): # unions for the file where we previously found # them. unionsForFilename = self.unionsPerFilename[f] - unionsForFilename = filter(lambda u: u.name != t.name, - unionsForFilename) + unionsForFilename = [u for u in unionsForFilename if u.name != t.name] if len(unionsForFilename) == 0: del self.unionsPerFilename[f] else: @@ -210,17 +209,17 @@ class Configuration(DescriptorProvider): getter = (lambda attrName: lambda x: getattr(x, attrName))(key) tofilter.append((getter, val)) for f in tofilter: - curr = filter(lambda x: f[0](x) == f[1], curr) + curr = [x for x in curr if f[0](x) == f[1]] return curr def getEnums(self, webIDLFile): - return filter(lambda e: e.filename() == webIDLFile, self.enums) + return [e for e in self.enums if e.filename() == webIDLFile] def getDictionaries(self, webIDLFile): - return filter(lambda d: d.filename() == webIDLFile, self.dictionaries) + return [d for d in self.dictionaries if d.filename() == webIDLFile] def getCallbacks(self, webIDLFile): - return filter(lambda c: c.filename() == webIDLFile, self.callbacks) + return [c for c in self.callbacks if c.filename() == webIDLFile] def getDescriptor(self, interfaceName): """ diff --git a/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py b/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py index 7356fc4149..20bd3e6db4 100755 --- a/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py +++ b/gfx/angle/src/libANGLE/renderer/gen_angle_format_table.py @@ -153,7 +153,7 @@ def get_component_type(format_id): def get_channel_tokens(format_id): r = re.compile(r'([ABDGLRS][\d]+)') - return filter(r.match, r.split(format_id)) + return list(filter(r.match, r.split(format_id))) def get_channels(format_id): channels = '' diff --git a/gfx/harfbuzz/src/gen-tag-table.py b/gfx/harfbuzz/src/gen-tag-table.py index 54817a6ed0..9fb595c116 100644 --- a/gfx/harfbuzz/src/gen-tag-table.py +++ b/gfx/harfbuzz/src/gen-tag-table.py @@ -872,7 +872,7 @@ bcp_47.remove_extra_macrolanguages () ot.inherit_from_macrolanguages () ot.names[DEFAULT_LANGUAGE_SYSTEM] = '*/' ot.ranks[DEFAULT_LANGUAGE_SYSTEM] = max (ot.ranks.values ()) + 1 -for tricky_ot_tag in filter (lambda tag: re.match ('[A-Z]{3}$', tag), ot.names): +for tricky_ot_tag in [tag for tag in ot.names if re.match ('[A-Z]{3}$', tag)]: possible_bcp_47_tag = tricky_ot_tag.lower () if possible_bcp_47_tag in bcp_47.names and not ot.from_bcp_47[possible_bcp_47_tag]: ot.add_language (possible_bcp_47_tag, DEFAULT_LANGUAGE_SYSTEM) diff --git a/gfx/skia/generate_mozbuild.py b/gfx/skia/generate_mozbuild.py index 1d1a2903b4..752fe300d8 100755 --- a/gfx/skia/generate_mozbuild.py +++ b/gfx/skia/generate_mozbuild.py @@ -312,7 +312,7 @@ def generate_separated_sources(platform_sources): else: f = open('skia/sources.json'); separated['pdf'].add('skia/src/core/SkMD5.cpp'); - separated['pdf'].update(filter(lambda x: 'pdf' in x, set(v.replace('../', 'skia/') for v in json.load(f)))); + separated['pdf'].update([x for x in set(v.replace('../', 'skia/') for v in json.load(f)) if 'pdf' in x]); f.close() return separated diff --git a/js/src/devtools/automation/autospider.py b/js/src/devtools/automation/autospider.py index 619362855c..63f88d6a6a 100755 --- a/js/src/devtools/automation/autospider.py +++ b/js/src/devtools/automation/autospider.py @@ -363,7 +363,7 @@ if variant.get('ignore-test-failures'): results = [0] if args.variant in ('tsan', 'msan'): - files = filter(lambda f: f.startswith("sanitize_log."), os.listdir(OUTDIR)) + files = [f for f in os.listdir(OUTDIR) if f.startswith("sanitize_log.")] fullfiles = [os.path.join(OUTDIR, f) for f in files] # Summarize results diff --git a/js/src/devtools/rootAnalysis/t/suppression/test.py b/js/src/devtools/rootAnalysis/t/suppression/test.py index 65974cc336..a4f3d5d563 100644 --- a/js/src/devtools/rootAnalysis/t/suppression/test.py +++ b/js/src/devtools/rootAnalysis/t/suppression/test.py @@ -9,9 +9,9 @@ suppressed = test.load_suppressed_functions() # Only one of these is fully suppressed (ie, *always* called within the scope # of an AutoSuppressGC). -assert(len(filter(lambda f: 'suppressedFunction' in f, suppressed)) == 1) -assert(len(filter(lambda f: 'halfSuppressedFunction' in f, suppressed)) == 0) -assert(len(filter(lambda f: 'unsuppressedFunction' in f, suppressed)) == 0) +assert(len([f for f in suppressed if 'suppressedFunction' in f]) == 1) +assert(len([f for f in suppressed if 'halfSuppressedFunction' in f]) == 0) +assert(len([f for f in suppressed if 'unsuppressedFunction' in f]) == 0) # gcFunctions should be the inverse, but we get to rely on unmangled names here. gcFunctions = test.load_gcFunctions() diff --git a/js/src/devtools/rootAnalysis/t/testlib.py b/js/src/devtools/rootAnalysis/t/testlib.py index 706e87bd7d..08f0a14b5b 100644 --- a/js/src/devtools/rootAnalysis/t/testlib.py +++ b/js/src/devtools/rootAnalysis/t/testlib.py @@ -46,7 +46,7 @@ class Test(object): if not isinstance(pattern, basestring): output = subprocess.check_output([self.binpath("xdbkeys"), dbname + ".xdb"]) - matches = filter(lambda _: re.search(pattern, _), output.splitlines()) + matches = [_ for _ in output.splitlines() if re.search(pattern, _)] if len(matches) == 0: raise Exception("entry not found") if len(matches) > 1: @@ -81,7 +81,7 @@ sixgill_bin = '{bindir}' def load_text_file(self, filename, extract=lambda l: l): fullpath = os.path.join(self.outdir, filename) values = (extract(line.strip()) for line in file(fullpath)) - return filter(lambda _: _ is not None, values) + return [_ for _ in values if _ is not None] def load_suppressed_functions(self): return set(self.load_text_file("suppressedFunctions.lst")) diff --git a/js/src/vm/make_unicode.py b/js/src/vm/make_unicode.py index 25bac1783b..673e83fb19 100755 --- a/js/src/vm/make_unicode.py +++ b/js/src/vm/make_unicode.py @@ -1345,7 +1345,7 @@ def make_irregexp_tables(version, character_range = partial(write_character_range, println) # Characters in \s, 21.2.2.12 CharacterClassEscape. - space_chars = filter(is_space, range(0, MAX_BMP + 1)) + space_chars = list(filter(is_space, range(0, MAX_BMP + 1))) # Characters in \d, 21.2.2.12 CharacterClassEscape. digit_chars = map(ord, string.digits) @@ -1357,7 +1357,7 @@ def make_irregexp_tables(version, # Characters which case-fold to characters in \w. ignorecase_word_chars = (word_chars + - filter(casefolds_to_ascii, range(MAX_ASCII + 1, MAX_BMP + 1))) + list(filter(casefolds_to_ascii, range(MAX_ASCII + 1, MAX_BMP + 1)))) # Surrogate characters. surrogate_chars = list(range(LEAD_SURROGATE_MIN, TRAIL_SURROGATE_MAX + 1)) diff --git a/layout/style/GenerateCSSPropsGenerated.py b/layout/style/GenerateCSSPropsGenerated.py index 5038e9afe7..d54fa3d7fe 100644 --- a/layout/style/GenerateCSSPropsGenerated.py +++ b/layout/style/GenerateCSSPropsGenerated.py @@ -66,7 +66,7 @@ def generate_assertions(properties): def generate_idl_name_positions(properties): # Skip aliases. - ps = filter(lambda p: p["proptype"] is not "alias", properties) + ps = [p for p in properties if p["proptype"] is not "alias"] # Sort alphabetically by IDL name. ps = sorted(ps, key=lambda p: p["idlname"]) diff --git a/media/libaom/generate_sources_mozbuild.py b/media/libaom/generate_sources_mozbuild.py index b62b8e3343..d219572f36 100644 --- a/media/libaom/generate_sources_mozbuild.py +++ b/media/libaom/generate_sources_mozbuild.py @@ -123,19 +123,19 @@ if __name__ == '__main__': # have to generate sources for each combination. if generate_sources: # Remove spurious sources and perl files - sources = filter(lambda x: x.startswith(AOM_DIR), sources) - sources = filter(lambda x: not x.endswith('.pl'), sources) + sources = [x for x in sources if x.startswith(AOM_DIR)] + sources = [x for x in sources if not x.endswith('.pl')] # Filter out exports - exports = filter(lambda x: re.match(os.path.join(AOM_DIR, '(aom|aom_mem|aom_ports|aom_scale)/.*h$'), x), sources) - exports = filter(lambda x: not re.search('(internal|src)', x), exports) - exports = filter(lambda x: not re.search('(emmintrin_compat.h|mem_.*|msvc.h|aom_once.h)$', x), exports) + exports = [x for x in sources if re.match(os.path.join(AOM_DIR, '(aom|aom_mem|aom_ports|aom_scale)/.*h$'), x)] + exports = [x for x in exports if not re.search('(internal|src)', x)] + exports = [x for x in exports if not re.search('(emmintrin_compat.h|mem_.*|msvc.h|aom_once.h)$', x)] for export in exports: sources.remove(export) # Remove header files - sources = sorted(filter(lambda x: not x.endswith('.h'), sources)) + sources = sorted([x for x in sources if not x.endswith('.h')]) # The build system is unhappy if two files have the same prefix # In libaom, sometimes .asm and .c files share the same prefix diff --git a/media/webrtc/trunk/build/android/pylib/json_perf_parser.py b/media/webrtc/trunk/build/android/pylib/json_perf_parser.py index 1a8e617539..7e105877f0 100644 --- a/media/webrtc/trunk/build/android/pylib/json_perf_parser.py +++ b/media/webrtc/trunk/build/android/pylib/json_perf_parser.py @@ -65,7 +65,7 @@ def GetAverageRunInfo(json_data, name): def EntryFilter(entry): return entry['cat'] == 'Java' and entry['name'] == name - filtered_entries = filter(EntryFilter, json_data) + filtered_entries = list(filter(EntryFilter, json_data)) result = {} diff --git a/media/webrtc/trunk/build/android/run_tests.py b/media/webrtc/trunk/build/android/run_tests.py index 5d513f5f3e..ad7abacee1 100755 --- a/media/webrtc/trunk/build/android/run_tests.py +++ b/media/webrtc/trunk/build/android/run_tests.py @@ -220,10 +220,8 @@ class TestSharder(BaseTestSharder): if not rebaseline: disabled_list = test.GetDisabledTests() # Only includes tests that do not have any match in the disabled list. - all_tests = filter(lambda t: - not any([fnmatch.fnmatch(t, disabled_pattern) - for disabled_pattern in disabled_list]), - all_tests) + all_tests = [t for t in all_tests if not any([fnmatch.fnmatch(t, disabled_pattern) + for disabled_pattern in disabled_list])] self.tests = all_tests def CreateShardedTestRunner(self, device, index): diff --git a/media/webrtc/trunk/tools/gyp/pylib/gyp/generator/make.py b/media/webrtc/trunk/tools/gyp/pylib/gyp/generator/make.py index 3e18b2fb80..7ac40a221e 100644 --- a/media/webrtc/trunk/tools/gyp/pylib/gyp/generator/make.py +++ b/media/webrtc/trunk/tools/gyp/pylib/gyp/generator/make.py @@ -793,7 +793,7 @@ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD gyp.xcode_emulation.MacPrefixHeader( self.xcode_settings, lambda p: Sourceify(self.Absolutify(p)), self.Pchify)) - sources = filter(Compilable, all_sources) + sources = list(filter(Compilable, all_sources)) if sources: self.WriteLn(SHARED_HEADER_SUFFIX_RULES_COMMENT1) extensions = set([os.path.splitext(s)[1] for s in sources]) @@ -1213,7 +1213,7 @@ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD includes = map(Sourceify, map(self.Absolutify, includes)) self.WriteList(includes, 'INCS_%s' % configname, prefix='-I') - compilable = filter(Compilable, sources) + compilable = list(filter(Compilable, sources)) objs = map(self.Objectify, map(self.Absolutify, map(Target, compilable))) self.WriteList(objs, 'OBJS') @@ -1286,7 +1286,7 @@ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD # If there are any object files in our input file list, link them into our # output. - extra_link_deps += filter(Linkable, sources) + extra_link_deps += list(filter(Linkable, sources)) self.WriteLn() @@ -1802,7 +1802,7 @@ $(obj).$(TOOLSET)/$(TARGET)/%%.o: $(obj)/%%%s FORCE_DO_CMD default_cpp_ext = ext self.WriteLn('LOCAL_CPP_EXTENSION := ' + default_cpp_ext) - self.WriteList(map(self.Absolutify, filter(Compilable, all_sources)), + self.WriteList(map(self.Absolutify, list(filter(Compilable, all_sources))), 'LOCAL_SRC_FILES') # Filter out those which do not match prefix and suffix and produce diff --git a/media/webrtc/trunk/tools/gyp/pylib/gyp/generator/ninja.py b/media/webrtc/trunk/tools/gyp/pylib/gyp/generator/ninja.py index 67d04b1054..2fb7f30217 100644 --- a/media/webrtc/trunk/tools/gyp/pylib/gyp/generator/ninja.py +++ b/media/webrtc/trunk/tools/gyp/pylib/gyp/generator/ninja.py @@ -350,7 +350,7 @@ class NinjaWriter(object): Uses a stamp file if necessary.""" - assert targets == filter(None, targets), targets + assert targets == [_f for _f in targets if _f], targets if len(targets) == 0: assert not order_only return None @@ -427,8 +427,8 @@ class NinjaWriter(object): compile_depends.append(target.PreCompileInput()) if target.uses_cpp: self.target.uses_cpp = True - actions_depends = filter(None, actions_depends) - compile_depends = filter(None, compile_depends) + actions_depends = [_f for _f in actions_depends if _f] + compile_depends = [_f for _f in compile_depends if _f] actions_depends = self.WriteCollapsedDependencies('actions_depends', actions_depends) compile_depends = self.WriteCollapsedDependencies('compile_depends', @@ -544,7 +544,7 @@ class NinjaWriter(object): if self.msvs_settings.HasExplicitIdlRulesOrActions(spec): return [] outputs = [] - for source in filter(lambda x: x.endswith('.idl'), spec['sources']): + for source in [x for x in spec['sources'] if x.endswith('.idl')]: self._WinIdlRule(source, prebuild, outputs) return outputs @@ -792,7 +792,7 @@ class NinjaWriter(object): output = self.GypPathToUniqueOutput('headers.hmap') self.xcode_settings.header_map_path = output all_headers = map(self.GypPathToNinja, - filter(lambda x:x.endswith(('.h')), all_sources)) + [x for x in all_sources if x.endswith(('.h'))]) variables = [('framework', framework), ('copy_headers', map(self.GypPathToNinja, copy_headers))] outputs.extend(self.ninja.build( diff --git a/media/webrtc/trunk/tools/gyp/pylib/gyp/mac_tool.py b/media/webrtc/trunk/tools/gyp/pylib/gyp/mac_tool.py index 37c8f21396..d13f0eefed 100755 --- a/media/webrtc/trunk/tools/gyp/pylib/gyp/mac_tool.py +++ b/media/webrtc/trunk/tools/gyp/pylib/gyp/mac_tool.py @@ -203,7 +203,7 @@ class MacTool(object): if lines[i].strip().startswith("${"): lines[i] = None lines[i - 1] = None - lines = '\n'.join(filter(lambda x: x is not None, lines)) + lines = '\n'.join([x for x in lines if x is not None]) # Write out the file with variables replaced. fd = open(dest, 'w') diff --git a/media/webrtc/trunk/tools/gyp/pylib/gyp/msvs_emulation.py b/media/webrtc/trunk/tools/gyp/pylib/gyp/msvs_emulation.py index e4a85a96e6..25d9a17918 100644 --- a/media/webrtc/trunk/tools/gyp/pylib/gyp/msvs_emulation.py +++ b/media/webrtc/trunk/tools/gyp/pylib/gyp/msvs_emulation.py @@ -94,7 +94,7 @@ def _DoRemapping(element, map): if not callable(map): map = map.get # Assume it's a dict, otherwise a callable to do the remap. if isinstance(element, list) or isinstance(element, tuple): - element = filter(None, [map(elem) for elem in element]) + element = [_f for _f in [map(elem) for elem in element] if _f] else: element = map(element) return element @@ -472,7 +472,7 @@ class MsvsSettings(object): # New flag required in 2013 to maintain previous PDB behavior. cflags.append('/FS') # ninja handles parallelism by itself, don't have the compiler do it too. - cflags = filter(lambda x: not x.startswith('/MP'), cflags) + cflags = [x for x in cflags if not x.startswith('/MP')] return cflags def _GetPchFlags(self, config, extension): @@ -638,8 +638,7 @@ class MsvsSettings(object): # If the base address is not specifically controlled, DYNAMICBASE should # be on by default. - base_flags = filter(lambda x: 'DYNAMICBASE' in x or x == '/FIXED', - ldflags) + base_flags = [x for x in ldflags if 'DYNAMICBASE' in x or x == '/FIXED'] if not base_flags: ldflags.append('/DYNAMICBASE') @@ -647,10 +646,10 @@ class MsvsSettings(object): # documentation that says this only defaults to on when the subsystem is # Vista or greater (which applies to the linker), the IDE defaults it on # unless it's explicitly off. - if not filter(lambda x: 'NXCOMPAT' in x, ldflags): + if not [x for x in ldflags if 'NXCOMPAT' in x]: ldflags.append('/NXCOMPAT') - have_def_file = filter(lambda x: x.startswith('/DEF:'), ldflags) + have_def_file = [x for x in ldflags if x.startswith('/DEF:')] manifest_flags, intermediate_manifest, manifest_files = \ self._GetLdManifestFlags(config, manifest_base_name, gyp_to_build_path, is_executable and not have_def_file, build_dir) @@ -1065,9 +1064,9 @@ def VerifyMissingSources(sources, build_dir, generator_flags, gyp_to_ninja): VS, and we want this check to match for people/bots that build using ninja, so they're not surprised when the VS build fails.""" if int(generator_flags.get('msvs_error_on_missing_sources', 0)): - no_specials = filter(lambda x: '$' not in x, sources) + no_specials = [x for x in sources if '$' not in x] relative = [os.path.join(build_dir, gyp_to_ninja(s)) for s in no_specials] - missing = filter(lambda x: not os.path.exists(x), relative) + missing = [x for x in relative if not os.path.exists(x)] if missing: # They'll look like out\Release\..\..\stuff\things.cc, so normalize the # path for a slightly less crazy looking output. diff --git a/media/webrtc/trunk/tools/gyp/pylib/gyp/ninja_syntax.py b/media/webrtc/trunk/tools/gyp/pylib/gyp/ninja_syntax.py index d2948f06c0..16ddc1f3d0 100644 --- a/media/webrtc/trunk/tools/gyp/pylib/gyp/ninja_syntax.py +++ b/media/webrtc/trunk/tools/gyp/pylib/gyp/ninja_syntax.py @@ -31,7 +31,7 @@ class Writer(object): if value is None: return if isinstance(value, list): - value = ' '.join(filter(None, value)) # Filter out empty strings. + value = ' '.join([_f for _f in value if _f]) # Filter out empty strings. self._line('%s = %s' % (key, value), indent) def pool(self, name, depth): diff --git a/media/webrtc/trunk/tools/gyp/test/lib/TestCmd.py b/media/webrtc/trunk/tools/gyp/test/lib/TestCmd.py index 050edde968..7361c97830 100644 --- a/media/webrtc/trunk/tools/gyp/test/lib/TestCmd.py +++ b/media/webrtc/trunk/tools/gyp/test/lib/TestCmd.py @@ -282,7 +282,7 @@ _chain_to_exitfunc = None def _clean(): global _Cleanup - cleanlist = filter(None, _Cleanup) + cleanlist = [_f for _f in _Cleanup if _f] del _Cleanup[:] cleanlist.reverse() for test in cleanlist: diff --git a/media/webrtc/trunk/tools/gyp/test/lib/TestCommon.py b/media/webrtc/trunk/tools/gyp/test/lib/TestCommon.py index 9839d01d73..422a36dbbe 100644 --- a/media/webrtc/trunk/tools/gyp/test/lib/TestCommon.py +++ b/media/webrtc/trunk/tools/gyp/test/lib/TestCommon.py @@ -239,7 +239,7 @@ class TestCommon(TestCmd): """ files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files) existing, missing = separate_files(files) - unwritable = filter(lambda x, iw=is_writable: not iw(x), existing) + unwritable = list(filter(lambda x, iw=is_writable: not iw(x), existing)) if missing: print("Missing files: `%s'" % string.join(missing, "', `")) if unwritable: @@ -324,7 +324,7 @@ class TestCommon(TestCmd): if any of the files does not exist. """ files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files) - missing = filter(lambda x: not os.path.exists(x), files) + missing = [x for x in files if not os.path.exists(x)] if missing: print("Missing files: `%s'" % string.join(missing, "', `")) self.fail_test(missing) @@ -396,7 +396,7 @@ class TestCommon(TestCmd): Exits FAILED if any of the files exists. """ files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files) - existing = filter(os.path.exists, files) + existing = list(filter(os.path.exists, files)) if existing: print("Unexpected files exist: `%s'" % string.join(existing, "', `")) self.fail_test(existing) @@ -410,7 +410,7 @@ class TestCommon(TestCmd): """ files = map(lambda x: is_List(x) and apply(os.path.join, x) or x, files) existing, missing = separate_files(files) - writable = filter(is_writable, existing) + writable = list(filter(is_writable, existing)) if missing: print("Missing files: `%s'" % string.join(missing, "', `")) if writable: diff --git a/media/webrtc/trunk/tools/gyp/test/mac/gyptest-strip-default.py b/media/webrtc/trunk/tools/gyp/test/mac/gyptest-strip-default.py index 2f04470fca..1633c4fb1a 100644 --- a/media/webrtc/trunk/tools/gyp/test/mac/gyptest-strip-default.py +++ b/media/webrtc/trunk/tools/gyp/test/mac/gyptest-strip-default.py @@ -34,7 +34,7 @@ if sys.platform == 'darwin': # Filter out mysterious "00 0000 OPT radr://5614542" symbol which # is apparently only printed on the bots (older toolchain?). # Yes, "radr", not "rdar". - o = ''.join(filter(lambda s: 'radr://5614542' not in s, o.splitlines(True))) + o = ''.join([s for s in o.splitlines(True) if 'radr://5614542' not in s]) o = o.replace('A', 'T') o = re.sub(r'^[a-fA-F0-9]+', 'XXXXXXXX', o, flags=re.MULTILINE) diff --git a/python/eme/gen-eme-voucher.py b/python/eme/gen-eme-voucher.py index 299bc71463..e7ddee20eb 100644 --- a/python/eme/gen-eme-voucher.py +++ b/python/eme/gen-eme-voucher.py @@ -129,8 +129,8 @@ def parse_items(stream, items_in, items_out): bits_read += bits total_bits_read += bits elif len(item) == 3 or len(item) == 4: - requirements = list(filter(lambda x: isinstance(x, dict), item[2])) - sub_items = list(filter(lambda x: isinstance(x, tuple), item[2])) + requirements = list([x for x in item[2] if isinstance(x, dict)]) + sub_items = list([x for x in item[2] if isinstance(x, tuple)]) if not meets_requirements(items_out, requirements): continue @@ -438,8 +438,8 @@ def processMachoBinary(filename): - segment_commands = list(filter(lambda x: x[0].cmd == lc_segment, header.commands)) - text_segment_commands = list(filter(lambda x: x[1].segname.decode("utf-8").startswith("__TEXT"), segment_commands)) + segment_commands = list([x for x in header.commands if x[0].cmd == lc_segment]) + text_segment_commands = list([x for x in segment_commands if x[1].segname.decode("utf-8").startswith("__TEXT")]) code_segment_digests = SetOfCodeSegmentDigest() @@ -518,7 +518,7 @@ def processCOFFBinary(stream): arch_digest.setComponentByName('cpuSubType', CPUSubType('IMAGE_UNUSED')) - text_section_headers = list(filter(lambda x: (x.items['Characteristics'] & IMAGE_SCN_MEM_EXECUTE) == IMAGE_SCN_MEM_EXECUTE, coff_header.section_headers)) + text_section_headers = list([x for x in coff_header.section_headers if (x.items['Characteristics'] & IMAGE_SCN_MEM_EXECUTE) == IMAGE_SCN_MEM_EXECUTE]) code_segment_digests = SetOfCodeSegmentDigest() code_segment_idx = 0 diff --git a/python/mach/mach/main.py b/python/mach/mach/main.py index dec3d7dfd7..51460f2fe1 100644 --- a/python/mach/mach/main.py +++ b/python/mach/mach/main.py @@ -542,7 +542,7 @@ To see more help for a specific command, run: return path files = map(find_in_dir, self.settings_paths) - files = filter(bool, files) + files = list(filter(bool, files)) self.settings.load_files(files) diff --git a/python/macholib/macholib/MachOStandalone.py b/python/macholib/macholib/MachOStandalone.py index f8627336ce..de8fd8f6b8 100644 --- a/python/macholib/macholib/MachOStandalone.py +++ b/python/macholib/macholib/MachOStandalone.py @@ -144,4 +144,4 @@ class MachOStandalone(object): flipwritable(fn, old_mode) allfiles = [mm.locate(node.filename) for node in machfiles] - return set(filter(None, allfiles)) + return set([_f for _f in allfiles if _f]) diff --git a/python/mozbuild/mozbuild/backend/recursivemake.py b/python/mozbuild/mozbuild/backend/recursivemake.py index 7f3b36c597..c9b167d420 100644 --- a/python/mozbuild/mozbuild/backend/recursivemake.py +++ b/python/mozbuild/mozbuild/backend/recursivemake.py @@ -269,8 +269,8 @@ class RecursiveMakeTraversal(object): Helper function to call a filter from compute_dependencies and traverse. """ - return filter(current, self._traversal.get(current, - self.SubDirectories())) + return list(filter(current, self._traversal.get(current, + self.SubDirectories()))) def compute_dependencies(self, filter=None): """ diff --git a/python/py/py/_code/code.py b/python/py/py/_code/code.py index f14c562a29..7d60410184 100644 --- a/python/py/py/_code/code.py +++ b/python/py/py/_code/code.py @@ -296,7 +296,7 @@ class Traceback(list): by default this removes all the TracebackItems which are hidden (see ishidden() above) """ - return Traceback(filter(fn, self)) + return Traceback(list(filter(fn, self))) def getcrashentry(self): """ return last non-hidden traceback entry that lead diff --git a/python/py/py/_log/log.py b/python/py/py/_log/log.py index ce47e8c754..42e7a948ff 100644 --- a/python/py/py/_log/log.py +++ b/python/py/py/_log/log.py @@ -92,7 +92,7 @@ class KeywordMapper: """ set a consumer for a set of keywords. """ # normalize to tuples if isinstance(keywords, str): - keywords = tuple(filter(None, keywords.split())) + keywords = tuple([_f for _f in keywords.split() if _f]) elif hasattr(keywords, '_keywords'): keywords = keywords._keywords elif not isinstance(keywords, tuple): diff --git a/python/py/py/_path/local.py b/python/py/py/_path/local.py index d569404ec2..42547bf50c 100644 --- a/python/py/py/_path/local.py +++ b/python/py/py/_path/local.py @@ -279,7 +279,7 @@ class LocalPath(FSBase): res = [] parts = self.strpath.split(self.sep) - args = filter(None, spec.split(',') ) + args = [_f for _f in spec.split(',') if _f] append = res.append for name in args: if name == 'drive': diff --git a/python/py/py/_path/svnurl.py b/python/py/py/_path/svnurl.py index 3ec4261ca3..36a9353a54 100644 --- a/python/py/py/_path/svnurl.py +++ b/python/py/py/_path/svnurl.py @@ -300,7 +300,7 @@ if verbose is True, then the LogEntry instances also know which files changed. from xml.dom import minidom tree = minidom.parse(xmlpipe) result = [] - for logentry in filter(None, tree.firstChild.childNodes): + for logentry in [_f for _f in tree.firstChild.childNodes if _f]: if logentry.nodeType == logentry.ELEMENT_NODE: result.append(svncommon.LogEntry(logentry)) return result diff --git a/python/py/py/_path/svnwc.py b/python/py/py/_path/svnwc.py index 00d3b4bbaf..4f20a75512 100644 --- a/python/py/py/_path/svnwc.py +++ b/python/py/py/_path/svnwc.py @@ -875,7 +875,7 @@ if verbose is True, then the LogEntry instances also know which files changed. except ExpatError: raise ValueError('no such revision') result = [] - for logentry in filter(None, tree.firstChild.childNodes): + for logentry in [_f for _f in tree.firstChild.childNodes if _f]: if logentry.nodeType == logentry.ELEMENT_NODE: result.append(LogEntry(logentry)) return result @@ -1215,7 +1215,7 @@ def importxml(cache=[]): class LogEntry: def __init__(self, logentry): self.rev = int(logentry.getAttribute('revision')) - for lpart in filter(None, logentry.childNodes): + for lpart in [_f for _f in logentry.childNodes if _f]: if lpart.nodeType == lpart.ELEMENT_NODE: if lpart.nodeName == 'author': self.author = lpart.firstChild.nodeValue @@ -1230,7 +1230,7 @@ class LogEntry: self.date = parse_apr_time(timestr) elif lpart.nodeName == 'paths': self.strpaths = [] - for ppart in filter(None, lpart.childNodes): + for ppart in [_f for _f in lpart.childNodes if _f]: if ppart.nodeType == ppart.ELEMENT_NODE: self.strpaths.append(PathEntry(ppart)) def __repr__(self): diff --git a/python/pystache/setup.py b/python/pystache/setup.py index ded27fb71a..0af1bb300d 100644 --- a/python/pystache/setup.py +++ b/python/pystache/setup.py @@ -200,7 +200,7 @@ def strip_html_comments(text): lines = text.splitlines(True) # preserve line endings. # Remove HTML comments (which we only allow to take a special form). - new_lines = filter(lambda line: not line.startswith("