From 9a73697c70e667c4655a01d3f76e5a9e850f1798 Mon Sep 17 00:00:00 2001 From: Charles Harris Date: Thu, 28 Feb 2013 13:19:41 -0700 Subject: REF: Replace filters with list comprehensions. 2to3 does a lot of list(filter(...)) sort of thing which can be avoided by using list comprehensions instead of filters. This also seems to clarify the code to a considerable degree. --- numpy/f2py/f2py2e.py | 29 +++++++++++++++++------------ 1 file changed, 17 insertions(+), 12 deletions(-) (limited to 'numpy/f2py/f2py2e.py') diff --git a/numpy/f2py/f2py2e.py b/numpy/f2py/f2py2e.py index 6efe00353..18402ced4 100755 --- a/numpy/f2py/f2py2e.py +++ b/numpy/f2py/f2py2e.py @@ -430,13 +430,14 @@ def run_compile(): remove_build_dir = 1 build_dir = os.path.join(tempfile.mktemp()) - sysinfo_flags = list(filter(re.compile(r'[-][-]link[-]').match,sys.argv[1:])) - sys.argv = list(filter(lambda a,flags=sysinfo_flags:a not in flags,sys.argv)) + sysinfo_flags = [_m for _m in sys.argv[1] if re.compile(r'[-][-]link[-]').match(_m)] + sys.argv = [_m for _m in sys.argv if not _m in sysinfo_flags] if sysinfo_flags: sysinfo_flags = [f[7:] for f in sysinfo_flags] - f2py_flags = list(filter(re.compile(r'[-][-]((no[-]|)(wrap[-]functions|lower)|debug[-]capi|quiet)|[-]include').match,sys.argv[1:])) - sys.argv = list(filter(lambda a,flags=f2py_flags:a not in flags,sys.argv)) + f2py_flags = [_m for _m in sys.argv[1:] if + re.compile(r'[-][-]((no[-]|)(wrap[-]functions|lower)|debug[-]capi|quiet)|[-]include').match(_m)] + sys.argv = [_m for _m in sys.argv if not _m in f2py_flags] f2py_flags2 = [] fl = 0 for a in sys.argv[1:]: @@ -450,12 +451,13 @@ def run_compile(): f2py_flags2.append(':') f2py_flags.extend(f2py_flags2) - sys.argv = list(filter(lambda a,flags=f2py_flags2:a not in flags,sys.argv)) - - flib_flags = list(filter(re.compile(r'[-][-]((f(90)?compiler([-]exec|)|compiler)=|help[-]compiler)').match,sys.argv[1:])) - sys.argv = list(filter(lambda a,flags=flib_flags:a not in flags,sys.argv)) - fc_flags = list(filter(re.compile(r'[-][-]((f(77|90)(flags|exec)|opt|arch)=|(debug|noopt|noarch|help[-]fcompiler))').match,sys.argv[1:])) - sys.argv = list(filter(lambda a,flags=fc_flags:a not in flags,sys.argv)) + sys.argv = [_m for _m in sys.argv if _m not in f2py_flags2] + flib_flags = [_m for _m in sys.argv[1:] if + re.compile(r'[-][-]((f(90)?compiler([-]exec|)|compiler)=|help[-]compiler)').match(_m)] + sys.argv = [_m for _m in sys.argv if not _m in flib_flags] + fc_flags = [_m for _m in sys.argv[1:] if + re.compile(r'[-][-]((f(77|90)(flags|exec)|opt|arch)=|(debug|noopt|noarch|help[-]fcompiler))').match(_m)] + sys.argv = [_m for _m in sys.argv if not _m in fc_flags] if 1: del_list = [] @@ -481,8 +483,11 @@ def run_compile(): i = flib_flags.index(s) del flib_flags[i] assert len(flib_flags)<=2,`flib_flags` - setup_flags = list(filter(re.compile(r'[-][-](verbose)').match,sys.argv[1:])) - sys.argv = list(filter(lambda a,flags=setup_flags:a not in flags,sys.argv)) + + setup_flags = [_m for _m in sys.argv[1:] if + re.compile(r'[-][-](verbose)').match(_m)] + sys.argv = [_m for _m in sys.argv if not _m in setup_flags] + if '--quiet' in f2py_flags: setup_flags.append('--quiet') -- cgit v1.2.1