From 41047b6902ea44ff4e3341b4dd749e18ff5c3fab Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Tue, 1 Oct 2024 17:13:54 +0200 Subject: [PATCH 1/5] A round of black to pass CI tests --- tabulate/__init__.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tabulate/__init__.py b/tabulate/__init__.py index c349a79..6b2a305 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -2685,11 +2685,14 @@ def _handle_long_word(self, reversed_chunks, cur_line, cur_len, width): if _ansi_codes.search(chunk) is not None: for group, _, _, _ in _ansi_codes.findall(chunk): escape_len = len(group) - if group in chunk[last_group: i + total_escape_len + escape_len - 1]: + if ( + group + in chunk[last_group : i + total_escape_len + escape_len - 1] + ): total_escape_len += escape_len found = _ansi_codes.search(chunk[last_group:]) last_group += found.end() - cur_line.append(chunk[: i + total_escape_len - 1]) + cur_line.append(chunk[: i + total_escape_len - 1]) reversed_chunks[-1] = chunk[i + total_escape_len - 1 :] # Otherwise, we have to preserve the long word intact. Only add From 85c04b06faecb9e7cb537b9a8a5eab7cd6a224d0 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 28 Sep 2024 00:41:46 +0200 Subject: [PATCH 2/5] Apply ruff rule RUF010 RUF010 Use explicit conversion flag --- test/test_api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_api.py b/test/test_api.py index 062573c..cf71231 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -26,7 +26,7 @@ def _check_signature(function, expected_sig): if not signature: skip("") actual_sig = signature(function) - print(f"expected: {expected_sig}\nactual: {str(actual_sig)}\n") + print(f"expected: {expected_sig}\nactual: {actual_sig}\n") assert len(actual_sig.parameters) == len(expected_sig) From cae715eee9d73b64159b04e893d5129aaeae63dc Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 28 Sep 2024 00:43:22 +0200 Subject: [PATCH 3/5] Apply ruff rule RUF021 RUF021 Parenthesize `a and b` expressions when chaining `and` and `or` together, to make the precedence clear --- tabulate/__init__.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 6b2a305..6259d61 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -2783,12 +2783,16 @@ def _wrap_chunks(self, chunks): self.max_lines is None or len(lines) + 1 < self.max_lines or ( - not chunks - or self.drop_whitespace - and len(chunks) == 1 - and not chunks[0].strip() + ( + not chunks + or ( + self.drop_whitespace + and len(chunks) == 1 + and not chunks[0].strip() + ) + ) + and cur_len <= width ) - and cur_len <= width ): # Convert current line back to a string and store it in # list of all lines (return value). From 8c9cffcbf5ebcc23440d502e0a23304403df4415 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 28 Sep 2024 00:44:05 +0200 Subject: [PATCH 4/5] Apply ruff ruile RUF022 RUF022 `__all__` is not sorted --- tabulate/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tabulate/__init__.py b/tabulate/__init__.py index 6259d61..fb5fdbd 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -23,7 +23,7 @@ def _is_file(f): return isinstance(f, io.IOBase) -__all__ = ["tabulate", "tabulate_formats", "simple_separated_format"] +__all__ = ["simple_separated_format", "tabulate", "tabulate_formats"] try: from .version import version as __version__ # noqa: F401 except ImportError: From 198b84d9d448f50fa8a7c261797c609618365206 Mon Sep 17 00:00:00 2001 From: Dimitri Papadopoulos <3234522+DimitriPapadopoulos@users.noreply.github.com> Date: Sat, 28 Sep 2024 00:44:47 +0200 Subject: [PATCH 5/5] Apply ruff rule RUF100 RUF100 Unused blanket `noqa` directive --- tabulate/__init__.py | 10 +++++----- test/common.py | 4 ++-- test/test_api.py | 6 +++--- test/test_internal.py | 4 ++-- test/test_output.py | 36 ++++++++++++++++++------------------ test/test_regression.py | 4 ++-- test/test_textwrapper.py | 6 +++--- 7 files changed, 35 insertions(+), 35 deletions(-) diff --git a/tabulate/__init__.py b/tabulate/__init__.py index fb5fdbd..f7dd5fb 100644 --- a/tabulate/__init__.py +++ b/tabulate/__init__.py @@ -25,7 +25,7 @@ def _is_file(f): __all__ = ["simple_separated_format", "tabulate", "tabulate_formats"] try: - from .version import version as __version__ # noqa: F401 + from .version import version as __version__ except ImportError: pass # running __init__.py as a script, AppVeyor pytests @@ -1090,7 +1090,7 @@ def _choose_width_fn(has_invisible, enable_widechars, is_multiline): else: line_width_fn = len if is_multiline: - width_fn = lambda s: _multiline_width(s, line_width_fn) # noqa + width_fn = lambda s: _multiline_width(s, line_width_fn) else: width_fn = line_width_fn return width_fn @@ -1130,7 +1130,7 @@ def _align_column_choose_width_fn(has_invisible, enable_widechars, is_multiline) else: line_width_fn = len if is_multiline: - width_fn = lambda s: _align_column_multiline_width(s, line_width_fn) # noqa + width_fn = lambda s: _align_column_multiline_width(s, line_width_fn) else: width_fn = line_width_fn return width_fn @@ -1261,7 +1261,7 @@ def _format(val, valtype, floatfmt, intfmt, missingval="", has_invisible=True): tabulate(tbl, headers=hrow) == good_result True - """ # noqa + """ if val is None: return missingval @@ -2542,7 +2542,7 @@ def _format_table( padded_widths = [(w + 2 * pad) for w in colwidths] if is_multiline: - pad_row = lambda row, _: row # noqa do it later, in _append_multiline_row + pad_row = lambda row, _: row append_row = partial(_append_multiline_row, pad=pad) else: pad_row = _pad_row diff --git a/test/common.py b/test/common.py index ec2fb35..58cfc52 100644 --- a/test/common.py +++ b/test/common.py @@ -1,5 +1,5 @@ -import pytest # noqa -from pytest import skip, raises # noqa +import pytest +from pytest import skip, raises import warnings diff --git a/test/test_api.py b/test/test_api.py index cf71231..e8c9ab2 100644 --- a/test/test_api.py +++ b/test/test_api.py @@ -19,7 +19,7 @@ def test_tabulate_formats(): print("tabulate_formats = %r" % supported) assert type(supported) is list for fmt in supported: - assert type(fmt) is str # noqa + assert type(fmt) is str def _check_signature(function, expected_sig): @@ -36,7 +36,7 @@ def _check_signature(function, expected_sig): def test_tabulate_signature(): "API: tabulate() type signature is unchanged" "" - assert type(tabulate) is type(lambda: None) # noqa + assert type(tabulate) is type(lambda: None) expected_sig = [ ("tabular_data", _empty), ("headers", ()), @@ -62,6 +62,6 @@ def test_tabulate_signature(): def test_simple_separated_format_signature(): "API: simple_separated_format() type signature is unchanged" "" - assert type(simple_separated_format) is type(lambda: None) # noqa + assert type(simple_separated_format) is type(lambda: None) expected_sig = [("separator", _empty)] _check_signature(simple_separated_format, expected_sig) diff --git a/test/test_internal.py b/test/test_internal.py index 17107c6..21af3a7 100644 --- a/test/test_internal.py +++ b/test/test_internal.py @@ -176,7 +176,7 @@ def test_wrap_text_to_colwidths(): def test_wrap_text_wide_chars(): "Internal: Wrap wide characters based on column width" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_wrap_text_wide_chars is skipped") @@ -242,7 +242,7 @@ def test_wrap_text_to_colwidths_single_ansi_colors_full_cell(): def test_wrap_text_to_colwidths_colors_wide_char(): """Internal: autowrapped text can retain a ANSI colors with wide chars""" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_wrap_text_to_colwidths_colors_wide_char is skipped") diff --git a/test/test_output.py b/test/test_output.py index 68b5e55..c3c9dc1 100644 --- a/test/test_output.py +++ b/test/test_output.py @@ -131,7 +131,7 @@ def test_plain_maxcolwidth_autowraps_with_sep(): def test_plain_maxcolwidth_autowraps_wide_chars(): "Output: maxcolwidth and autowrapping functions with wide characters" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_wrap_text_wide_chars is skipped") @@ -492,7 +492,7 @@ def test_grid(): def test_grid_wide_characters(): "Output: grid with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_grid_wide_characters is skipped") headers = list(_test_table_headers) @@ -627,7 +627,7 @@ def test_simple_grid(): def test_simple_grid_wide_characters(): "Output: simple_grid with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_simple_grid_wide_characters is skipped") headers = list(_test_table_headers) @@ -762,7 +762,7 @@ def test_rounded_grid(): def test_rounded_grid_wide_characters(): "Output: rounded_grid with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_rounded_grid_wide_characters is skipped") headers = list(_test_table_headers) @@ -897,7 +897,7 @@ def test_heavy_grid(): def test_heavy_grid_wide_characters(): "Output: heavy_grid with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_heavy_grid_wide_characters is skipped") headers = list(_test_table_headers) @@ -1032,7 +1032,7 @@ def test_mixed_grid(): def test_mixed_grid_wide_characters(): "Output: mixed_grid with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_mixed_grid_wide_characters is skipped") headers = list(_test_table_headers) @@ -1167,7 +1167,7 @@ def test_double_grid(): def test_double_grid_wide_characters(): "Output: double_grid with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_double_grid_wide_characters is skipped") headers = list(_test_table_headers) @@ -1302,7 +1302,7 @@ def test_fancy_grid(): def test_fancy_grid_wide_characters(): "Output: fancy_grid with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_fancy_grid_wide_characters is skipped") headers = list(_test_table_headers) @@ -1471,7 +1471,7 @@ def test_colon_grid(): def test_colon_grid_wide_characters(): "Output: colon_grid with wide chars in header" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_colon_grid_wide_characters is skipped") headers = list(_test_table_headers) @@ -1565,7 +1565,7 @@ def test_outline(): def test_outline_wide_characters(): "Output: outline with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_outline_wide_characters is skipped") headers = list(_test_table_headers) @@ -1617,7 +1617,7 @@ def test_simple_outline(): def test_simple_outline_wide_characters(): "Output: simple_outline with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_simple_outline_wide_characters is skipped") headers = list(_test_table_headers) @@ -1669,7 +1669,7 @@ def test_rounded_outline(): def test_rounded_outline_wide_characters(): "Output: rounded_outline with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_rounded_outline_wide_characters is skipped") headers = list(_test_table_headers) @@ -1721,7 +1721,7 @@ def test_heavy_outline(): def test_heavy_outline_wide_characters(): "Output: heavy_outline with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_heavy_outline_wide_characters is skipped") headers = list(_test_table_headers) @@ -1773,7 +1773,7 @@ def test_mixed_outline(): def test_mixed_outline_wide_characters(): "Output: mixed_outline with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_mixed_outline_wide_characters is skipped") headers = list(_test_table_headers) @@ -1825,7 +1825,7 @@ def test_double_outline(): def test_double_outline_wide_characters(): "Output: double_outline with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_double_outline_wide_characters is skipped") headers = list(_test_table_headers) @@ -1877,7 +1877,7 @@ def test_fancy_outline(): def test_fancy_outline_wide_characters(): "Output: fancy_outline with wide characters in headers" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_fancy_outline_wide_characters is skipped") headers = list(_test_table_headers) @@ -2536,7 +2536,7 @@ def test_html(): [ "", "", - '', # noqa + '', "", "", '', @@ -2557,7 +2557,7 @@ def test_unsafehtml(): [ "
<strings> <&numbers&>
<strings> <&numbers&>
spam > 41.9999
", "", - "", # noqa + "", "", "", '', diff --git a/test/test_regression.py b/test/test_regression.py index bf26247..46654c8 100644 --- a/test/test_regression.py +++ b/test/test_regression.py @@ -300,7 +300,7 @@ class textclass(str): def test_mix_normal_and_wide_characters(): "Regression: wide characters in a grid format (issue #51)" try: - import wcwidth # noqa + import wcwidth ru_text = "\u043f\u0440\u0438\u0432\u0435\u0442" cn_text = "\u4f60\u597d" @@ -322,7 +322,7 @@ def test_mix_normal_and_wide_characters(): def test_multiline_with_wide_characters(): "Regression: multiline tables with varying number of wide characters (github issue #28)" try: - import wcwidth # noqa + import wcwidth table = [["가나\n가ab", "가나", "가나"]] result = tabulate(table, tablefmt="fancy_grid") diff --git a/test/test_textwrapper.py b/test/test_textwrapper.py index 8c0a6cc..ebc7d41 100644 --- a/test/test_textwrapper.py +++ b/test/test_textwrapper.py @@ -47,7 +47,7 @@ def test_wrap_longword_non_wide(): def test_wrap_wide_char_multiword(): """TextWrapper: wrapping support for wide characters with multiple words""" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_wrap_wide_char is skipped") @@ -63,7 +63,7 @@ def test_wrap_wide_char_multiword(): def test_wrap_wide_char_longword(): """TextWrapper: wrapping wide char word that needs to be broken up""" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_wrap_wide_char_longword is skipped") @@ -80,7 +80,7 @@ def test_wrap_wide_char_longword(): def test_wrap_mixed_string(): """TextWrapper: wrapping string with mix of wide and non-wide chars""" try: - import wcwidth # noqa + import wcwidth except ImportError: skip("test_wrap_wide_char is skipped")
strings numbers
strings numbers
spam 41.9999