summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2022-09-07 14:03:41 -0700
committerEli Schwartz <eschwartz@archlinux.org>2022-11-29 23:26:05 -0500
commitd5e899c76808d45854a06a4ba2b006da32480165 (patch)
treeeb2f315230d2448edce06fa1a82666d683b2d6bb
parenta5d547e0d9ccb523f0baab7fd32e782aa075fb42 (diff)
downloadmeson-d5e899c76808d45854a06a4ba2b006da32480165.tar.gz
pylint: enable the bad_builtin checker
This finds uses of deny-listed functions, which defaults to map and filter. These functions should be replaced by comprehensions in idiomatic python because: 1. comprehensions are more heavily optimized and are often faster 2. They avoid the need for lambdas in some cases, which make them faster 3. you can do the equivalent in one statement rather than two, which is faster 4. They're easier to read 5. if you need a concrete instance (ie, a list) then you don't have to convert the iterator to a list afterwards
-rw-r--r--.pylintrc2
-rw-r--r--mesonbuild/backend/ninjabackend.py4
-rw-r--r--mesonbuild/backend/xcodebackend.py2
-rw-r--r--mesonbuild/cmake/common.py2
-rw-r--r--mesonbuild/cmake/traceparser.py2
-rw-r--r--mesonbuild/dependencies/cmake.py2
-rw-r--r--mesonbuild/interpreter/interpreter.py2
-rw-r--r--mesonbuild/interpreter/interpreterobjects.py2
-rw-r--r--mesonbuild/mcompile.py8
-rw-r--r--mesonbuild/minit.py2
-rw-r--r--mesonbuild/modules/external_project.py2
-rw-r--r--mesonbuild/utils/universal.py4
12 files changed, 17 insertions, 17 deletions
diff --git a/.pylintrc b/.pylintrc
index 5b01181d3..493185c36 100644
--- a/.pylintrc
+++ b/.pylintrc
@@ -1,5 +1,7 @@
[MASTER]
jobs=0
+load-plugins=
+ pylint.extensions.bad_builtin,
[REPORTS]
score=no
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index aed4fd06a..7f478239e 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -209,8 +209,8 @@ class NinjaRule:
return NinjaCommandArg(c)
self.name = rule
- self.command = list(map(strToCommandArg, command)) # includes args which never go into a rspfile
- self.args = list(map(strToCommandArg, args)) # args which will go into a rspfile, if used
+ self.command = [strToCommandArg(c) for c in command] # includes args which never go into a rspfile
+ self.args = [strToCommandArg(a) for a in args] # args which will go into a rspfile, if used
self.description = description
self.deps = deps # depstyle 'gcc' or 'msvc'
self.depfile = depfile
diff --git a/mesonbuild/backend/xcodebackend.py b/mesonbuild/backend/xcodebackend.py
index 9e101ce63..c56036bfd 100644
--- a/mesonbuild/backend/xcodebackend.py
+++ b/mesonbuild/backend/xcodebackend.py
@@ -541,7 +541,7 @@ class XCodeBackend(backends.Backend):
self.custom_aggregate_targets = {}
self.build_all_tdep_id = self.gen_id()
# FIXME: filter out targets that are not built by default.
- target_dependencies = list(map(lambda t: self.pbx_dep_map[t], self.build_targets))
+ target_dependencies = [self.pbx_dep_map[t] for t in self.build_targets]
custom_target_dependencies = [self.pbx_custom_dep_map[t] for t in self.custom_targets]
aggregated_targets = []
aggregated_targets.append((self.all_id, 'ALL_BUILD',
diff --git a/mesonbuild/cmake/common.py b/mesonbuild/cmake/common.py
index 7c05a2ba2..85598daa1 100644
--- a/mesonbuild/cmake/common.py
+++ b/mesonbuild/cmake/common.py
@@ -111,7 +111,7 @@ def _flags_to_list(raw: str) -> T.List[str]:
else:
curr += i
res += [curr]
- res = list(filter(lambda x: len(x) > 0, res))
+ res = [r for r in res if len(r) > 0]
return res
def cmake_get_generator_args(env: 'Environment') -> T.List[str]:
diff --git a/mesonbuild/cmake/traceparser.py b/mesonbuild/cmake/traceparser.py
index d8b97a230..ef8ea39de 100644
--- a/mesonbuild/cmake/traceparser.py
+++ b/mesonbuild/cmake/traceparser.py
@@ -747,7 +747,7 @@ class CMakeTraceParser:
func = mo_file_line.group(4)
args = mo_file_line.group(5)
argl = args.split(' ')
- argl = list(map(lambda x: x.strip(), argl))
+ argl = [a.strip() for a in argl]
yield CMakeTraceLine(file, int(line), func, argl)
diff --git a/mesonbuild/dependencies/cmake.py b/mesonbuild/dependencies/cmake.py
index a035c7dd4..abd31a138 100644
--- a/mesonbuild/dependencies/cmake.py
+++ b/mesonbuild/dependencies/cmake.py
@@ -510,7 +510,7 @@ class CMakeDependency(ExternalDependency):
# Try to use old style variables if no module is specified
if len(libs) > 0:
- self.compile_args = list(map(lambda x: f'-I{x}', incDirs)) + defs
+ self.compile_args = [f'-I{x}' for x in incDirs] + defs
self.link_args = []
for j in libs:
rtgt = resolve_cmake_trace_targets(j, self.traceparser, self.env, clib_compiler=self.clib_compiler)
diff --git a/mesonbuild/interpreter/interpreter.py b/mesonbuild/interpreter/interpreter.py
index c34f9ab75..d5afaf3af 100644
--- a/mesonbuild/interpreter/interpreter.py
+++ b/mesonbuild/interpreter/interpreter.py
@@ -2555,7 +2555,7 @@ class Interpreter(InterpreterBase, HoldableObject):
mesonlib.do_conf_file(inputs_abs[0], ofile_abs, conf,
fmt, file_encoding)
if missing_variables:
- var_list = ", ".join(map(repr, sorted(missing_variables)))
+ var_list = ", ".join(repr(m) for m in sorted(missing_variables))
mlog.warning(
f"The variable(s) {var_list} in the input file '{inputs[0]}' are not "
"present in the given configuration data.", location=node)
diff --git a/mesonbuild/interpreter/interpreterobjects.py b/mesonbuild/interpreter/interpreterobjects.py
index cac33a40e..00412a0f2 100644
--- a/mesonbuild/interpreter/interpreterobjects.py
+++ b/mesonbuild/interpreter/interpreterobjects.py
@@ -81,7 +81,7 @@ def extract_search_dirs(kwargs: 'kwargs.ExtractSearchDirs') -> T.List[str]:
continue
if not d.is_absolute():
raise InvalidCode(f'Search directory {d} is not an absolute path.')
- return list(map(str, search_dirs))
+ return [str(s) for s in search_dirs]
class FeatureOptionHolder(ObjectHolder[coredata.UserFeatureOption]):
def __init__(self, option: coredata.UserFeatureOption, interpreter: 'Interpreter'):
diff --git a/mesonbuild/mcompile.py b/mesonbuild/mcompile.py
index 2e6829c2d..27ef46ce0 100644
--- a/mesonbuild/mcompile.py
+++ b/mesonbuild/mcompile.py
@@ -190,11 +190,9 @@ def get_parsed_args_vs(options: 'argparse.Namespace', builddir: Path) -> T.Tuple
if options.targets:
intro_data = parse_introspect_data(builddir)
- has_run_target = any(map(
- lambda t:
- get_target_from_intro_data(ParsedTargetName(t), builddir, intro_data)['type'] == 'run',
- options.targets
- ))
+ has_run_target = any(
+ get_target_from_intro_data(ParsedTargetName(t), builddir, intro_data)['type'] == 'run'
+ for t in options.targets)
if has_run_target:
# `run` target can't be used the same way as other targets on `vs` backend.
diff --git a/mesonbuild/minit.py b/mesonbuild/minit.py
index 70815633b..e92358268 100644
--- a/mesonbuild/minit.py
+++ b/mesonbuild/minit.py
@@ -97,7 +97,7 @@ def autodetect_options(options: 'argparse.Namespace', sample: bool = False) -> N
raise SystemExit('No recognizable source files found.\n'
'Run meson init in an empty directory to create a sample project.')
options.srcfiles = srcfiles
- print("Detected source files: " + ' '.join(map(str, srcfiles)))
+ print("Detected source files: " + ' '.join(str(s) for s in srcfiles))
options.srcfiles = [Path(f) for f in options.srcfiles]
if not options.language:
for f in options.srcfiles:
diff --git a/mesonbuild/modules/external_project.py b/mesonbuild/modules/external_project.py
index dbbd84f88..c3b01c8c5 100644
--- a/mesonbuild/modules/external_project.py
+++ b/mesonbuild/modules/external_project.py
@@ -191,7 +191,7 @@ class ExternalProject(NewExtensionModule):
missing.update(missing_vars)
out.append(arg)
if missing:
- var_list = ", ".join(map(repr, sorted(missing)))
+ var_list = ", ".join(repr(m) for m in sorted(missing))
raise EnvironmentException(
f"Variables {var_list} in configure options are missing.")
return out
diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py
index 9fa590bb4..f58a124e9 100644
--- a/mesonbuild/utils/universal.py
+++ b/mesonbuild/utils/universal.py
@@ -26,7 +26,7 @@ import abc
import platform, subprocess, operator, os, shlex, shutil, re
import collections
from functools import lru_cache, wraps, total_ordering
-from itertools import tee, filterfalse
+from itertools import tee
from tempfile import TemporaryDirectory, NamedTemporaryFile
import typing as T
import textwrap
@@ -1399,7 +1399,7 @@ def partition(pred: T.Callable[[_T], object], iterable: T.Iterable[_T]) -> T.Tup
([0, 2, 4, 6, 8], [1, 3, 5, 7, 9])
"""
t1, t2 = tee(iterable)
- return filterfalse(pred, t1), filter(pred, t2)
+ return (t for t in t1 if not pred(t)), (t for t in t2 if pred(t))
def Popen_safe(args: T.List[str], write: T.Optional[str] = None,