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
pull/11117/head
Dylan Baker 2 years ago committed by Eli Schwartz
parent a5d547e0d9
commit d5e899c768
No known key found for this signature in database
GPG Key ID: CEB167EFB5722BD6
  1. 2
      .pylintrc
  2. 4
      mesonbuild/backend/ninjabackend.py
  3. 2
      mesonbuild/backend/xcodebackend.py
  4. 2
      mesonbuild/cmake/common.py
  5. 2
      mesonbuild/cmake/traceparser.py
  6. 2
      mesonbuild/dependencies/cmake.py
  7. 2
      mesonbuild/interpreter/interpreter.py
  8. 2
      mesonbuild/interpreter/interpreterobjects.py
  9. 8
      mesonbuild/mcompile.py
  10. 2
      mesonbuild/minit.py
  11. 2
      mesonbuild/modules/external_project.py
  12. 4
      mesonbuild/utils/universal.py

@ -1,5 +1,7 @@
[MASTER]
jobs=0
load-plugins=
pylint.extensions.bad_builtin,
[REPORTS]
score=no

@ -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

@ -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',

@ -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]:

@ -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)

@ -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)

@ -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)

@ -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'):

@ -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.

@ -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:

@ -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

@ -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,

Loading…
Cancel
Save