From d5e899c76808d45854a06a4ba2b006da32480165 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Wed, 7 Sep 2022 14:03:41 -0700 Subject: 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 --- mesonbuild/utils/universal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'mesonbuild/utils/universal.py') diff --git a/mesonbuild/utils/universal.py b/mesonbuild/utils/universal.py index 9fa590b..f58a124 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, -- cgit v1.1