Skip to content

Commit

Permalink
Fix UP031 Use format specifiers instead of percent format
Browse files Browse the repository at this point in the history
  • Loading branch information
hugovk committed Jan 7, 2025
1 parent 43abeee commit 225c8ac
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/humanize/filesize.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ def naturalsize(
abs_bytes = abs(bytes_)

if abs_bytes == 1 and not gnu:
return "%d Byte" % bytes_
return f"{bytes_} Byte"

if abs_bytes < base:
return ("%dB" if gnu else "%d Bytes") % bytes_
return f"{bytes_}B" if gnu else f"{bytes_} Bytes"

for i, s in enumerate(suffix, 2):
unit = base**i
Expand Down
2 changes: 1 addition & 1 deletion src/humanize/number.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,7 @@ def metric(value: float, unit: str = "", precision: int = 3) -> str:
ordinal_ = "mμnpfazyrq"[(-exponent - 1) // 3]
else:
ordinal_ = ""
value_ = format(value, ".%if" % max(0, precision - (exponent % 3) - 1))
value_ = format(value, f".{int(max(0, precision - exponent % 3 - 1))}f")
if not (unit or ordinal_) or unit in ("°", "′", "″"):
space = ""
else:
Expand Down

0 comments on commit 225c8ac

Please sign in to comment.