aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-09-07 15:23:42 -0700
committerEli Schwartz <eschwartz@archlinux.org>2022-10-04 00:33:04 -0400
commita72840cd2e27bf18b88cf95ef6a9e5e3ab05427d (patch)
treec3e6ce969bd01ae144f14213dd591e022c453019
parentf11ebf20ff51dc1e9d6aa07fea64bc891869e48a (diff)
downloadmeson-a72840cd2e27bf18b88cf95ef6a9e5e3ab05427d.zip
meson-a72840cd2e27bf18b88cf95ef6a9e5e3ab05427d.tar.gz
meson-a72840cd2e27bf18b88cf95ef6a9e5e3ab05427d.tar.bz2
pylint: enable use-a-generator
This catches some optimization problems, mostly in the use of `all()` and `any()`. Basically writing `any([x == 5 for x in f])` vs `any(x == 5 for x in f)` reduces the performance because the entire concrete list must first be created, then iterated over, while in the second f is iterated and checked element by element.
-rw-r--r--.pylintrc1
-rw-r--r--mesonbuild/cmake/common.py2
-rw-r--r--mesonbuild/cmake/generator.py4
-rw-r--r--mesonbuild/cmake/interpreter.py14
-rw-r--r--mesonbuild/cmake/traceparser.py2
-rw-r--r--mesonbuild/dependencies/boost.py14
-rw-r--r--mesonbuild/dependencies/cmake.py2
-rw-r--r--mesonbuild/modules/cmake.py2
-rw-r--r--mesonbuild/modules/gnome.py2
9 files changed, 21 insertions, 22 deletions
diff --git a/.pylintrc b/.pylintrc
index e30b0f7..926d7c7 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -75,7 +75,6 @@ disable=
unsubscriptable-object,
unused-argument,
unused-variable,
- use-a-generator,
use-implicit-booleaness-not-comparison,
used-before-assignment,
useless-return,
diff --git a/mesonbuild/cmake/common.py b/mesonbuild/cmake/common.py
index 60764cc..7c05a2b 100644
--- a/mesonbuild/cmake/common.py
+++ b/mesonbuild/cmake/common.py
@@ -151,7 +151,7 @@ def check_cmake_args(args: T.List[str]) -> T.List[str]:
dis = ['-D' + x for x in blacklist_cmake_defs]
assert dis # Ensure that dis is not empty.
for i in args:
- if any([i.startswith(x) for x in dis]):
+ if any(i.startswith(x) for x in dis):
mlog.warning('Setting', mlog.bold(i), 'is not supported. See the meson docs for cross compilation support:')
mlog.warning(' - URL: https://mesonbuild.com/CMake-module.html#cross-compilation')
mlog.warning(' --> Ignoring this option')
diff --git a/mesonbuild/cmake/generator.py b/mesonbuild/cmake/generator.py
index a4224cc..d7a281a 100644
--- a/mesonbuild/cmake/generator.py
+++ b/mesonbuild/cmake/generator.py
@@ -100,8 +100,8 @@ def parse_generator_expressions(
supported = {
# Boolean functions
'BOOL': lambda x: '0' if x.upper() in ['0', 'FALSE', 'OFF', 'N', 'NO', 'IGNORE', 'NOTFOUND'] or x.endswith('-NOTFOUND') else '1',
- 'AND': lambda x: '1' if all([y == '1' for y in x.split(',')]) else '0',
- 'OR': lambda x: '1' if any([y == '1' for y in x.split(',')]) else '0',
+ 'AND': lambda x: '1' if all(y == '1' for y in x.split(',')) else '0',
+ 'OR': lambda x: '1' if any(y == '1' for y in x.split(',')) else '0',
'NOT': lambda x: '0' if x == '1' else '1',
'IF': lambda x: x.split(',')[1] if x.split(',')[0] == '1' else x.split(',')[2],
diff --git a/mesonbuild/cmake/interpreter.py b/mesonbuild/cmake/interpreter.py
index b15b48d..dc63942 100644
--- a/mesonbuild/cmake/interpreter.py
+++ b/mesonbuild/cmake/interpreter.py
@@ -372,8 +372,8 @@ class ConverterTarget:
for i in self.languages:
supported += list(lang_suffixes[i])
supported = [f'.{x}' for x in supported]
- self.sources = [x for x in self.sources if any([x.name.endswith(y) for y in supported])]
- self.generated_raw = [x for x in self.generated_raw if any([x.name.endswith(y) for y in supported])]
+ self.sources = [x for x in self.sources if any(x.name.endswith(y) for y in supported)]
+ self.generated_raw = [x for x in self.generated_raw if any(x.name.endswith(y) for y in supported)]
# Make paths relative
def rel_path(x: Path, is_header: bool, is_generated: bool) -> T.Optional[Path]:
@@ -381,7 +381,7 @@ class ConverterTarget:
x = self.src_dir / x
x = x.resolve()
assert x.is_absolute()
- if not x.exists() and not any([x.name.endswith(y) for y in obj_suffixes]) and not is_generated:
+ if not x.exists() and not any(x.name.endswith(y) for y in obj_suffixes) and not is_generated:
if path_is_in_root(x, Path(self.env.get_build_dir()), resolve=True):
x.mkdir(parents=True, exist_ok=True)
return x.relative_to(Path(self.env.get_build_dir()) / subdir)
@@ -471,7 +471,7 @@ class ConverterTarget:
def process_object_libs(self, obj_target_list: T.List['ConverterTarget'], linker_workaround: bool) -> None:
# Try to detect the object library(s) from the generated input sources
- temp = [x for x in self.generated if any([x.name.endswith('.' + y) for y in obj_suffixes])]
+ temp = [x for x in self.generated if any(x.name.endswith('.' + y) for y in obj_suffixes)]
stem = [x.stem for x in temp]
exts = self._all_source_suffixes()
# Temp now stores the source filenames of the object files
@@ -484,10 +484,10 @@ class ConverterTarget:
# undo this step and guess the correct language suffix of the object file. This is done
# by trying all language suffixes meson knows and checking if one of them fits.
candidates = [j] # type: T.List[str]
- if not any([j.endswith('.' + x) for x in exts]):
+ if not any(j.endswith('.' + x) for x in exts):
mlog.warning('Object files do not contain source file extensions, thus falling back to guessing them.', once=True)
candidates += [f'{j}.{x}' for x in exts]
- if any([x in source_files for x in candidates]):
+ if any(x in source_files for x in candidates):
if linker_workaround:
self._append_objlib_sources(i)
else:
@@ -497,7 +497,7 @@ class ConverterTarget:
break
# Filter out object files from the sources
- self.generated = [x for x in self.generated if not any([x.name.endswith('.' + y) for y in obj_suffixes])]
+ self.generated = [x for x in self.generated if not any(x.name.endswith('.' + y) for y in obj_suffixes)]
def _append_objlib_sources(self, tgt: 'ConverterTarget') -> None:
self.includes += tgt.includes
diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py
index d9b5f45..d8b97a2 100644
--- a/mesonbuild/cmake/traceparser.py
+++ b/mesonbuild/cmake/traceparser.py
@@ -83,7 +83,7 @@ class CMakeTarget:
return
for key, val in self.properties.items():
self.properties[key] = [x.strip() for x in val]
- assert all([';' not in x for x in self.properties[key]])
+ assert all(';' not in x for x in self.properties[key])
class CMakeGeneratorTarget(CMakeTarget):
def __init__(self, name: str) -> None:
diff --git a/mesonbuild/dependencies/boost.py b/mesonbuild/dependencies/boost.py
index cb432a3..2a901ce 100644
--- a/mesonbuild/dependencies/boost.py
+++ b/mesonbuild/dependencies/boost.py
@@ -237,10 +237,10 @@ class BoostLibraryFile():
return abitag
def is_boost(self) -> bool:
- return any([self.name.startswith(x) for x in ['libboost_', 'boost_']])
+ return any(self.name.startswith(x) for x in ['libboost_', 'boost_'])
def is_python_lib(self) -> bool:
- return any([self.mod_name.startswith(x) for x in BoostLibraryFile.boost_python_libs])
+ return any(self.mod_name.startswith(x) for x in BoostLibraryFile.boost_python_libs)
def fix_python_name(self, tags: T.List[str]) -> T.List[str]:
# Handle the boost_python naming madeness.
@@ -438,7 +438,7 @@ class BoostDependency(SystemDependency):
raw_paths = mesonlib.stringlistify(rootdir)
paths = [Path(x) for x in raw_paths]
- if paths and any([not x.is_absolute() for x in paths]):
+ if paths and any(not x.is_absolute() for x in paths):
raise DependencyException('boost_root path given in machine file must be absolute')
self.check_and_set_roots(paths, use_system=False)
@@ -574,13 +574,13 @@ class BoostDependency(SystemDependency):
arch_list_64 = ['64']
raw_list = dirs + subdirs
- no_arch = [x for x in raw_list if not any([y in x.name for y in arch_list_32 + arch_list_64])]
+ no_arch = [x for x in raw_list if not any(y in x.name for y in arch_list_32 + arch_list_64)]
matching_arch = [] # type: T.List[Path]
if '32' in self.arch:
- matching_arch = [x for x in raw_list if any([y in x.name for y in arch_list_32])]
+ matching_arch = [x for x in raw_list if any(y in x.name for y in arch_list_32)]
elif '64' in self.arch:
- matching_arch = [x for x in raw_list if any([y in x.name for y in arch_list_64])]
+ matching_arch = [x for x in raw_list if any(y in x.name for y in arch_list_64)]
return sorted(matching_arch) + sorted(no_arch)
@@ -626,7 +626,7 @@ class BoostDependency(SystemDependency):
for i in libdir.iterdir():
if not i.is_file():
continue
- if not any([i.name.startswith(x) for x in ['libboost_', 'boost_']]):
+ if not any(i.name.startswith(x) for x in ['libboost_', 'boost_']):
continue
# Windows binaries from SourceForge ship with PDB files alongside
# DLLs (#8325). Ignore them.
diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py
index e5443dd..a035c7d 100644
--- a/mesonbuild/dependencies/cmake.py
+++ b/mesonbuild/dependencies/cmake.py
@@ -272,7 +272,7 @@ class CMakeDependency(ExternalDependency):
content = self._cached_listdir(i)
candidates = ['Find{}.cmake', '{}Config.cmake', '{}-config.cmake']
candidates = [x.format(name).lower() for x in candidates]
- if any([x[1] in candidates for x in content]):
+ if any(x[1] in candidates for x in content):
return True
return False
diff --git a/mesonbuild/modules/cmake.py b/mesonbuild/modules/cmake.py
index a46c399..ee40b44 100644
--- a/mesonbuild/modules/cmake.py
+++ b/mesonbuild/modules/cmake.py
@@ -130,7 +130,7 @@ class CMakeSubproject(ModuleObject):
' message(\'CMake targets:\\n - \' + \'\\n - \'.join(<cmake_subproject>.target_list()))')
# Make sure that all keys are present (if not this is a bug)
- assert all([x in res for x in ['inc', 'src', 'dep', 'tgt', 'func']])
+ assert all(x in res for x in ['inc', 'src', 'dep', 'tgt', 'func'])
return res
@noKwargs
diff --git a/mesonbuild/modules/gnome.py b/mesonbuild/modules/gnome.py
index 4287b13..0112ab1 100644
--- a/mesonbuild/modules/gnome.py
+++ b/mesonbuild/modules/gnome.py
@@ -1118,7 +1118,7 @@ class GnomeModule(ExtensionModule):
def generate_gir(self, state: 'ModuleState', args: T.Tuple[T.List[T.Union[build.Executable, build.SharedLibrary, build.StaticLibrary]]],
kwargs: 'GenerateGir') -> ModuleReturnValue:
girtargets = [self._unwrap_gir_target(arg, state) for arg in args[0]]
- if len(girtargets) > 1 and any([isinstance(el, build.Executable) for el in girtargets]):
+ if len(girtargets) > 1 and any(isinstance(el, build.Executable) for el in girtargets):
raise MesonException('generate_gir only accepts a single argument when one of the arguments is an executable')
gir_dep, giscanner, gicompiler = self._get_gir_dep(state)