diff --git a/benchmark/benchmark.py b/benchmark/benchmark.py index 2fd1e3a..d405f5c 100644 --- a/benchmark/benchmark.py +++ b/benchmark/benchmark.py @@ -75,7 +75,7 @@ def benchmark(n): methods = [m for m in methods if m[0].startswith("tabulate")] 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])] table = tabulate.tabulate( results, ["Table formatter", "time, μs", "rel. time"], "rst", floatfmt=".1f" diff --git a/pyproject.toml b/pyproject.toml index 2a80daa..11397bb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -53,7 +53,7 @@ line-length = 99 exclude = ["tabulate/_version.py"] [tool.ruff.lint] -extend-select = ["W", "ISC", "I", "C90"] +extend-select = ["W", "C4", "ISC", "I", "C90"] ignore = ["E721", "C901"] [tool.ruff.lint.mccabe] diff --git a/tabulate/__init__.py b/tabulate/__init__.py index b0810a9..38e1708 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -1592,7 +1592,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] @@ -2381,7 +2381,7 @@ def tabulate( assert isinstance(colalign, Iterable) if isinstance(colalign, str): warnings.warn( - f"As a string, `colalign` is interpreted as {[c for c in colalign]}. " + f"As a string, `colalign` is interpreted as {list(colalign)}. " f'Did you mean `colglobalalign = "{colalign}"` or `colalign = ("{colalign}",)`?', stacklevel=2, ) @@ -2423,7 +2423,7 @@ def tabulate( assert isinstance(headersalign, Iterable) if isinstance(headersalign, str): warnings.warn( - f"As a string, `headersalign` is interpreted as {[c for c in headersalign]}. " + f"As a string, `headersalign` is interpreted as {list(headersalign)}. " f'Did you mean `headersglobalalign = "{headersalign}"` ' f'or `headersalign = ("{headersalign}",)`?', stacklevel=2, @@ -2702,7 +2702,7 @@ def _update_lines(self, lines, new_line): as add any colors from previous lines order to preserve the same formatting as a single unwrapped string. """ - code_matches = [x for x in _ansi_codes.finditer(new_line)] + code_matches = list(_ansi_codes.finditer(new_line)) color_codes = [code.string[code.span()[0] : code.span()[1]] for code in code_matches] # Add color codes from earlier in the unwrapped line, and then track any new ones we add. diff --git a/test/common.py b/test/common.py index b557b85..5f00852 100644 --- a/test/common.py +++ b/test/common.py @@ -41,6 +41,6 @@ def check_warnings(func_args_kwargs, *, num=None, category=None, contain=None): if num is not None: assert len(W) == num if category is not None: - assert all([issubclass(w.category, category) for w in W]) + assert all(issubclass(w.category, category) for w in W) if contain is not None: - assert all([contain in str(w.message) for w in W]) + assert all(contain in str(w.message) for w in W) diff --git a/test/test_regression.py b/test/test_regression.py index c23d34d..6172180 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -171,7 +171,7 @@ def test_numeric_column_headers(): expected = " 42\n----\n 1\n 2" assert_equal(expected, result) - lod = [{p: i for p in range(5)} for i in range(5)] + lod = [dict.fromkeys(range(5), i) for i in range(5)] result = tabulate(lod, "keys") expected = "\n".join( [