Skip to content
Browse files

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.
  • Loading branch information...
1 parent b990ed5 commit 9a73697c70e667c4655a01d3f76e5a9e850f1798 @charris charris committed Feb 28, 2013
View
2 numpy/distutils/command/build_py.py
@@ -21,7 +21,7 @@ def find_package_modules(self, package, package_dir):
def find_modules(self):
old_py_modules = self.py_modules[:]
- new_py_modules = list(filter(is_string, self.py_modules))
+ new_py_modules = [_m for _m in self.py_modules if is_string(_m)]
self.py_modules[:] = new_py_modules
modules = old_build_py.find_modules(self)
self.py_modules[:] = old_py_modules
View
8 numpy/distutils/misc_util.py
@@ -555,7 +555,7 @@ def general_source_directories_files(top_path):
def get_ext_source_files(ext):
# Get sources and any include files in the same directory.
filenames = []
- sources = list(filter(is_string, ext.sources))
+ sources = [_m for _m in ext.sources if is_string(_m)]
filenames.extend(sources)
filenames.extend(get_dependencies(sources))
for d in ext.depends:
@@ -566,13 +566,13 @@ def get_ext_source_files(ext):
return filenames
def get_script_files(scripts):
- scripts = list(filter(is_string, scripts))
+ scripts = [_m for _m in scripts if is_string(_m)]
return scripts
def get_lib_source_files(lib):
filenames = []
sources = lib[1].get('sources',[])
- sources = list(filter(is_string, sources))
+ sources = [_m for _m in sources if is_string(_m)]
filenames.extend(sources)
filenames.extend(get_dependencies(sources))
depends = lib[1].get('depends',[])
@@ -808,7 +808,7 @@ def _wildcard_get_subpackage(self, subpackage_name,
caller_level = 1):
l = subpackage_name.split('.')
subpackage_path = njoin([self.local_path]+l)
- dirs = list(filter(os.path.isdir,glob.glob(subpackage_path)))
+ dirs = [_m for _m in glob.glob(subpackage_path) if os.path.isdir(_m)]
config_list = []
for d in dirs:
if not os.path.isfile(njoin(d,'__init__.py')):
View
6 numpy/distutils/system_info.py
@@ -232,9 +232,9 @@ def libpaths(paths, bits):
default_include_dirs.append(os.path.join(sys.prefix, 'include'))
default_src_dirs.append(os.path.join(sys.prefix, 'src'))
-default_lib_dirs = list(filter(os.path.isdir, default_lib_dirs))
-default_include_dirs = list(filter(os.path.isdir, default_include_dirs))
-default_src_dirs = list(filter(os.path.isdir, default_src_dirs))
+default_lib_dirs = [_m for _m in default_lib_dirs if os.path.isdir(_m)]
+default_include_dirs = [_m for _m in default_include_dirs if os.path.isdir(_m)]
+default_src_dirs = [_m for _m in default_src_dirs if os.path.isdir(_m)]
so_ext = get_shared_lib_extension()
View
29 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')
View
2 numpy/testing/utils.py
@@ -1050,7 +1050,7 @@ def decorate_methods(cls, decorator, testmatch=None):
# delayed import to reduce startup time
from inspect import isfunction
- methods = list(filter(isfunction, cls_attr.values()))
+ methods = [_m for _m in cls_attr.values() if isfunction(_m)]
for function in methods:
try:
if hasattr(function, 'compat_func_name'):

0 comments on commit 9a73697

Please sign in to comment.
Something went wrong with that request. Please try again.