From 7c1a3e5de636969877bc593e257f772cfffb6004 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Thu, 26 Sep 2024 18:54:19 +0200 Subject: [PATCH] Apply ruff/flake8-comprehensions rule C417 C417 Unnecessary `map` usage (rewrite using a generator expression) --- benchmark/benchmark.py | 2 +- tabulate/__init__.py | 2 +- test/test_input.py | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index a89b709..466d27e 100644 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -75,7 +75,7 @@ def benchmark(n): results = [ (desc, timeit(code, setup_code, number=n) / n * 1e6) for desc, code in methods ] - mintime = min(map(lambda x: x[1], results)) + mintime = min((x[1] for x in results)) results = [ (desc, t, t / mintime) for desc, t in sorted(results, key=lambda x: x[1]) ] diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 7548914..ef8780d 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -1548,7 +1548,7 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"): headers = list(map(str, headers)) # rows = list(map(list, rows)) - rows = list(map(lambda r: r if _is_separating_line(r) else list(r), rows)) + rows = [r if _is_separating_line(r) else list(r) for r in rows] # add or remove an index column showindex_is_a_str = type(showindex) in [str, bytes] diff --git a/test/test_input.py b/test/test_input.py index b910a34..9ddc4b7 100644 --- a/test/test_input.py +++ b/test/test_input.py @@ -12,7 +12,7 @@ def test_iterable_of_iterables(): "Input: an iterable of iterables." - ii = iter(map(lambda x: iter(x), [range(5), range(5, 0, -1)])) + ii = iter((iter(x) for x in [range(5), range(5, 0, -1)])) expected = "\n".join( ["- - - - -", "0 1 2 3 4", "5 4 3 2 1", "- - - - -"] ) @@ -22,7 +22,7 @@ def test_iterable_of_iterables(): def test_iterable_of_iterables_headers(): "Input: an iterable of iterables with headers." - ii = iter(map(lambda x: iter(x), [range(5), range(5, 0, -1)])) + ii = iter((iter(x) for x in [range(5), range(5, 0, -1)])) expected = "\n".join( [ " a b c d e", @@ -37,7 +37,7 @@ def test_iterable_of_iterables_headers(): def test_iterable_of_iterables_firstrow(): "Input: an iterable of iterables with the first row as headers" - ii = iter(map(lambda x: iter(x), ["abcde", range(5), range(5, 0, -1)])) + ii = iter((iter(x) for x in ["abcde", range(5), range(5, 0, -1)])) expected = "\n".join( [ " a b c d e",