Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

2to3: Apply `filter` fixes. Closes #3053.

Generally, this involves using list comprehension, or explicit list
construction as `filter` is an iterator in Python 3.
  • Loading branch information...
commit b990ed5a18b58715fa1e13642bc7f6761e597818 1 parent 0934653
@charris charris authored
View
2  numpy/_import_tools.py
@@ -207,7 +207,7 @@ def __call__(self,*packages, **options):
if symbols is None:
symbols = eval('dir(%s)' % (package_name),
frame.f_globals,frame.f_locals)
- symbols = filter(lambda s:not s.startswith('_'),symbols)
+ symbols = [s for s in symbols if not s.startswith('_')]
else:
symbols = [symbol]
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 = filter(is_string, self.py_modules)
+ new_py_modules = list(filter(is_string, self.py_modules))
self.py_modules[:] = new_py_modules
modules = old_build_py.find_modules(self)
self.py_modules[:] = old_py_modules
View
4 numpy/distutils/command/build_src.py
@@ -186,8 +186,8 @@ def build_data_files_sources(self):
build_dir = self.get_package_dir('.'.join(d.split(os.sep)))
else:
build_dir = os.path.join(self.build_src,d)
- funcs = filter(lambda f:hasattr(f, '__call__'), files)
- files = filter(lambda f:not hasattr(f, '__call__'), files)
+ funcs = [f for f in files if hasattr(f, '__call__')]
+ files = [f for f in files if not hasattr(f, '__call__')]
for f in funcs:
if f.func_code.co_argcount==1:
s = f(build_dir)
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 = filter(is_string, ext.sources)
+ sources = list(filter(is_string, ext.sources))
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 = filter(is_string, scripts)
+ scripts = list(filter(is_string, scripts))
return scripts
def get_lib_source_files(lib):
filenames = []
sources = lib[1].get('sources',[])
- sources = filter(is_string, sources)
+ sources = list(filter(is_string, sources))
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 = filter(os.path.isdir,glob.glob(subpackage_path))
+ dirs = list(filter(os.path.isdir,glob.glob(subpackage_path)))
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 = filter(os.path.isdir, default_lib_dirs)
-default_include_dirs = filter(os.path.isdir, default_include_dirs)
-default_src_dirs = filter(os.path.isdir, default_src_dirs)
+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))
so_ext = get_shared_lib_extension()
View
22 numpy/f2py/f2py2e.py
@@ -430,13 +430,13 @@ def run_compile():
remove_build_dir = 1
build_dir = os.path.join(tempfile.mktemp())
- sysinfo_flags = filter(re.compile(r'[-][-]link[-]').match,sys.argv[1:])
- sys.argv = filter(lambda a,flags=sysinfo_flags:a not in flags,sys.argv)
+ 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))
if sysinfo_flags:
sysinfo_flags = [f[7:] for f in sysinfo_flags]
- f2py_flags = filter(re.compile(r'[-][-]((no[-]|)(wrap[-]functions|lower)|debug[-]capi|quiet)|[-]include').match,sys.argv[1:])
- sys.argv = filter(lambda a,flags=f2py_flags:a not in flags,sys.argv)
+ 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_flags2 = []
fl = 0
for a in sys.argv[1:]:
@@ -450,12 +450,12 @@ def run_compile():
f2py_flags2.append(':')
f2py_flags.extend(f2py_flags2)
- sys.argv = filter(lambda a,flags=f2py_flags2:a not in flags,sys.argv)
+ sys.argv = list(filter(lambda a,flags=f2py_flags2:a not in flags,sys.argv))
- flib_flags = filter(re.compile(r'[-][-]((f(90)?compiler([-]exec|)|compiler)=|help[-]compiler)').match,sys.argv[1:])
- sys.argv = filter(lambda a,flags=flib_flags:a not in flags,sys.argv)
- fc_flags = filter(re.compile(r'[-][-]((f(77|90)(flags|exec)|opt|arch)=|(debug|noopt|noarch|help[-]fcompiler))').match,sys.argv[1:])
- sys.argv = filter(lambda a,flags=fc_flags: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))
if 1:
del_list = []
@@ -481,8 +481,8 @@ def run_compile():
i = flib_flags.index(s)
del flib_flags[i]
assert len(flib_flags)<=2,`flib_flags`
- setup_flags = filter(re.compile(r'[-][-](verbose)').match,sys.argv[1:])
- sys.argv = filter(lambda a,flags=setup_flags:a not in flags,sys.argv)
+ 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))
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 = filter(isfunction, cls_attr.values())
+ methods = list(filter(isfunction, cls_attr.values()))
for function in methods:
try:
if hasattr(function, 'compat_func_name'):
View
2  setup.py
@@ -50,7 +50,7 @@
URL = "http://www.numpy.org"
DOWNLOAD_URL = "http://sourceforge.net/projects/numpy/files/NumPy/"
LICENSE = 'BSD'
-CLASSIFIERS = filter(None, CLASSIFIERS.split('\n'))
+CLASSIFIERS = [_f for _f in CLASSIFIERS.split('\n') if _f]
AUTHOR = "Travis E. Oliphant et al."
AUTHOR_EMAIL = "oliphant@enthought.com"
PLATFORMS = ["Windows", "Linux", "Solaris", "Mac OS-X", "Unix"]
Please sign in to comment.
Something went wrong with that request. Please try again.