Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ def run_tabulate(table, widechars=False):
methods = [
("join with tabs and newlines", "join_table(table)"),
("csv to StringIO", "csv_table(table)"),
("tabulate (%s)" % tabulate.__version__, "run_tabulate(table)"),
(f"tabulate ({tabulate.__version__})", "run_tabulate(table)"),
(
"tabulate (%s, WIDE_CHARS_MODE)" % tabulate.__version__,
f"tabulate ({tabulate.__version__}, WIDE_CHARS_MODE)",
"run_tabulate(table, widechars=True)",
),
("PrettyTable (%s)" % prettytable.__version__, "run_prettytable(table)"),
("texttable (%s)" % texttable.__version__, "run_texttable(table)"),
(f"PrettyTable ({prettytable.__version__})", "run_prettytable(table)"),
(f"texttable ({texttable.__version__})", "run_texttable(table)"),
]


Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ line-length = 99
exclude = ["tabulate/_version.py"]

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

[tool.ruff.lint.mccabe]
Expand Down
15 changes: 7 additions & 8 deletions tabulate/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Pretty-print tabular data."""

from collections import namedtuple
from collections.abc import Iterable, Sized
from collections.abc import Callable, Iterable, Sized
import dataclasses
from dataclasses import dataclass
from decimal import Decimal
Expand All @@ -14,7 +14,6 @@
import re
import sys
import textwrap
from typing import Callable, Union
import warnings

try:
Expand Down Expand Up @@ -1046,7 +1045,7 @@ def _padleft(width, s):
True

"""
fmt = "{0:>%ds}" % width
fmt = f"{{0:>{width}s}}"
return fmt.format(s)


Expand All @@ -1057,7 +1056,7 @@ def _padright(width, s):
True

"""
fmt = "{0:<%ds}" % width
fmt = f"{{0:<{width}s}}"
return fmt.format(s)


Expand All @@ -1068,7 +1067,7 @@ def _padboth(width, s):
True

"""
fmt = "{0:^%ds}" % width
fmt = f"{{0:^{width}s}}"
return fmt.format(s)


Expand Down Expand Up @@ -2529,7 +2528,7 @@ def _build_row(
padded_cells: list[list],
colwidths: list[int],
colaligns: list[str],
rowfmt: Union[DataRow, Callable],
rowfmt: DataRow | Callable,
) -> str:
"Return a string which represents a row of data cells."
if not rowfmt:
Expand Down Expand Up @@ -2805,7 +2804,7 @@ def _wrap_chunks(self, chunks):
"""
lines = []
if self.width <= 0:
raise ValueError("invalid width %r (must be > 0)" % self.width)
raise ValueError(f"invalid width {self.width!r} (must be > 0)")
if self.max_lines is not None:
if self.max_lines > 1:
indent = self.subsequent_indent
Expand Down Expand Up @@ -2962,7 +2961,7 @@ def _main():
colalign = value.split()
elif opt in ["-f", "--format"]:
if value not in tabulate_formats:
print("%s is not a supported table format" % value)
print(f"{value} is not a supported table format")
print(usage)
sys.exit(3)
tablefmt = value
Expand Down
8 changes: 4 additions & 4 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@


def assert_equal(expected, result):
print("Expected:\n%r\n" % expected)
print("Got:\n%r\n" % result)
print(f"Expected:\n{expected!r}\n")
print(f"Got:\n{result!r}\n")
assert expected == result


def assert_in(result, expected_set):
for i, expected in enumerate(expected_set, start=1):
print("Expected %d:\n%s\n" % (i, expected))
print("Got:\n%s\n" % result)
print(f"Expected {i}:\n{expected}\n")
print(f"Got:\n{result}\n")
assert result in expected_set


Expand Down
2 changes: 1 addition & 1 deletion test/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
def test_tabulate_formats():
"API: tabulate_formats is a list of strings"
supported = tabulate_formats
print("tabulate_formats = %r" % supported)
print(f"tabulate_formats = {supported!r}")
assert type(supported) is list
for fmt in supported:
assert type(fmt) is str
Expand Down
2 changes: 1 addition & 1 deletion test/test_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ def test_dict_like():
expected1 = "\n".join([" a b", "--- ---", " 0 101", " 1 102", " 2 103", " 104"])
expected2 = "\n".join([" b a", "--- ---", "101 0", "102 1", "103 2", "104"])
result = tabulate(dd, "keys")
print("Keys' order: %s" % dd.keys())
print(f"Keys' order: {dd.keys()}")
assert_in(result, [expected1, expected2])


Expand Down
2 changes: 1 addition & 1 deletion test/test_regression.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ def test_multiline_with_wide_characters():

def test_align_long_integers():
"Regression: long integers should be aligned as integers (issue #61)"
table = [[int(1)], [int(234)]]
table = [[1], [234]]
result = tabulate(table, tablefmt="plain")
expected = "\n".join([" 1", "234"])
assert_equal(expected, result)
Expand Down