Skip to content

Commit 5313627

Browse files
authored
Merge branch 'master' into dev/jsonl
2 parents cf15727 + 2070736 commit 5313627

File tree

7 files changed

+18
-19
lines changed

7 files changed

+18
-19
lines changed

benchmark/benchmark.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ def run_tabulate(table, widechars=False):
5555
methods = [
5656
("join with tabs and newlines", "join_table(table)"),
5757
("csv to StringIO", "csv_table(table)"),
58-
("tabulate (%s)" % tabulate.__version__, "run_tabulate(table)"),
58+
(f"tabulate ({tabulate.__version__})", "run_tabulate(table)"),
5959
(
60-
"tabulate (%s, WIDE_CHARS_MODE)" % tabulate.__version__,
60+
f"tabulate ({tabulate.__version__}, WIDE_CHARS_MODE)",
6161
"run_tabulate(table, widechars=True)",
6262
),
63-
("PrettyTable (%s)" % prettytable.__version__, "run_prettytable(table)"),
64-
("texttable (%s)" % texttable.__version__, "run_texttable(table)"),
63+
(f"PrettyTable ({prettytable.__version__})", "run_prettytable(table)"),
64+
(f"texttable ({texttable.__version__})", "run_texttable(table)"),
6565
]
6666

6767

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ line-length = 99
5656
exclude = ["tabulate/_version.py"]
5757

5858
[tool.ruff.lint]
59-
extend-select = ["W", "C4", "ISC", "I", "C90"]
59+
extend-select = ["W", "C4", "ISC", "I", "C90", "UP"]
6060
ignore = ["E721", "C901"]
6161

6262
[tool.ruff.lint.mccabe]

tabulate/__init__.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Pretty-print tabular data."""
22

33
from collections import namedtuple
4-
from collections.abc import Iterable, Sized
4+
from collections.abc import Callable, Iterable, Sized
55
import dataclasses
66
from dataclasses import dataclass
77
from decimal import Decimal
@@ -13,7 +13,6 @@
1313
import math
1414
import re
1515
import textwrap
16-
from typing import Callable, Union
1716
import warnings
1817

1918
try:
@@ -1045,7 +1044,7 @@ def _padleft(width, s):
10451044
True
10461045
10471046
"""
1048-
fmt = "{0:>%ds}" % width
1047+
fmt = f"{{0:>{width}s}}"
10491048
return fmt.format(s)
10501049

10511050

@@ -1056,7 +1055,7 @@ def _padright(width, s):
10561055
True
10571056
10581057
"""
1059-
fmt = "{0:<%ds}" % width
1058+
fmt = f"{{0:<{width}s}}"
10601059
return fmt.format(s)
10611060

10621061

@@ -1067,7 +1066,7 @@ def _padboth(width, s):
10671066
True
10681067
10691068
"""
1070-
fmt = "{0:^%ds}" % width
1069+
fmt = f"{{0:^{width}s}}"
10711070
return fmt.format(s)
10721071

10731072

@@ -2528,7 +2527,7 @@ def _build_row(
25282527
padded_cells: list[list],
25292528
colwidths: list[int],
25302529
colaligns: list[str],
2531-
rowfmt: Union[DataRow, Callable],
2530+
rowfmt: DataRow | Callable,
25322531
) -> str:
25332532
"Return a string which represents a row of data cells."
25342533
if not rowfmt:
@@ -2804,7 +2803,7 @@ def _wrap_chunks(self, chunks):
28042803
"""
28052804
lines = []
28062805
if self.width <= 0:
2807-
raise ValueError("invalid width %r (must be > 0)" % self.width)
2806+
raise ValueError(f"invalid width {self.width!r} (must be > 0)")
28082807
if self.max_lines is not None:
28092808
if self.max_lines > 1:
28102809
indent = self.subsequent_indent

test/common.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@
55

66

77
def assert_equal(expected, result):
8-
print("Expected:\n%r\n" % expected)
9-
print("Got:\n%r\n" % result)
8+
print(f"Expected:\n{expected!r}\n")
9+
print(f"Got:\n{result!r}\n")
1010
assert expected == result
1111

1212

1313
def assert_in(result, expected_set):
1414
for i, expected in enumerate(expected_set, start=1):
15-
print("Expected %d:\n%s\n" % (i, expected))
16-
print("Got:\n%s\n" % result)
15+
print(f"Expected {i}:\n{expected}\n")
16+
print(f"Got:\n{result}\n")
1717
assert result in expected_set
1818

1919

test/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
def test_tabulate_formats():
1515
"API: tabulate_formats is a list of strings"
1616
supported = tabulate_formats
17-
print("tabulate_formats = %r" % supported)
17+
print(f"tabulate_formats = {supported!r}")
1818
assert type(supported) is list
1919
for fmt in supported:
2020
assert type(fmt) is str

test/test_input.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ def test_dict_like():
9696
expected1 = "\n".join([" a b", "--- ---", " 0 101", " 1 102", " 2 103", " 104"])
9797
expected2 = "\n".join([" b a", "--- ---", "101 0", "102 1", "103 2", "104"])
9898
result = tabulate(dd, "keys")
99-
print("Keys' order: %s" % dd.keys())
99+
print(f"Keys' order: {dd.keys()}")
100100
assert_in(result, [expected1, expected2])
101101

102102

test/test_regression.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ def test_multiline_with_wide_characters():
341341

342342
def test_align_long_integers():
343343
"Regression: long integers should be aligned as integers (issue #61)"
344-
table = [[int(1)], [int(234)]]
344+
table = [[1], [234]]
345345
result = tabulate(table, tablefmt="plain")
346346
expected = "\n".join([" 1", "234"])
347347
assert_equal(expected, result)

0 commit comments

Comments
 (0)