Skip to content

Commit b565dc4

Browse files
Apply ruff/pyupgrade rule UP031
Use format specifiers instead of percent format
1 parent 64b3976 commit b565dc4

5 files changed

Lines changed: 15 additions & 15 deletions

File tree

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

tabulate/__init__.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ def _padleft(width, s):
10461046
True
10471047
10481048
"""
1049-
fmt = "{0:>%ds}" % width
1049+
fmt = f"{{0:>{width}s}}"
10501050
return fmt.format(s)
10511051

10521052

@@ -1057,7 +1057,7 @@ def _padright(width, s):
10571057
True
10581058
10591059
"""
1060-
fmt = "{0:<%ds}" % width
1060+
fmt = f"{{0:<{width}s}}"
10611061
return fmt.format(s)
10621062

10631063

@@ -1068,7 +1068,7 @@ def _padboth(width, s):
10681068
True
10691069
10701070
"""
1071-
fmt = "{0:^%ds}" % width
1071+
fmt = f"{{0:^{width}s}}"
10721072
return fmt.format(s)
10731073

10741074

@@ -2805,7 +2805,7 @@ def _wrap_chunks(self, chunks):
28052805
"""
28062806
lines = []
28072807
if self.width <= 0:
2808-
raise ValueError("invalid width %r (must be > 0)" % self.width)
2808+
raise ValueError(f"invalid width {self.width!r} (must be > 0)")
28092809
if self.max_lines is not None:
28102810
if self.max_lines > 1:
28112811
indent = self.subsequent_indent
@@ -2962,7 +2962,7 @@ def _main():
29622962
colalign = value.split()
29632963
elif opt in ["-f", "--format"]:
29642964
if value not in tabulate_formats:
2965-
print("%s is not a supported table format" % value)
2965+
print(f"{value} is not a supported table format")
29662966
print(usage)
29672967
sys.exit(3)
29682968
tablefmt = value

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

0 commit comments

Comments
 (0)