Skip to content

Commit c692722

Browse files
authored
Merge pull request #29 from hugovk/fix-types
2 parents 3ddae94 + 7cc0245 commit c692722

File tree

3 files changed

+15
-13
lines changed

3 files changed

+15
-13
lines changed

src/humanize/filesize.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,22 @@ def naturalsize(
5555
suffix = suffixes["decimal"]
5656

5757
base = 1024 if (gnu or binary) else 1000
58-
bytes = float(value)
59-
abs_bytes = abs(bytes)
58+
bytes_ = float(value)
59+
abs_bytes = abs(bytes_)
6060

6161
if abs_bytes == 1 and not gnu:
62-
return "%d Byte" % bytes
62+
return "%d Byte" % bytes_
6363
elif abs_bytes < base and not gnu:
64-
return "%d Bytes" % bytes
64+
return "%d Bytes" % bytes_
6565
elif abs_bytes < base and gnu:
66-
return "%dB" % bytes
66+
return "%dB" % bytes_
6767

6868
for i, s in enumerate(suffix):
6969
unit = base ** (i + 2)
7070
if abs_bytes < unit and not gnu:
71-
return (format + " %s") % ((base * bytes / unit), s)
71+
return (format + " %s") % ((base * bytes_ / unit), s)
7272
elif abs_bytes < unit and gnu:
73-
return (format + "%s") % ((base * bytes / unit), s)
73+
return (format + "%s") % ((base * bytes_ / unit), s)
7474
if gnu:
75-
return (format + "%s") % ((base * bytes / unit), s)
76-
return (format + " %s") % ((base * bytes / unit), s)
75+
return (format + "%s") % ((base * bytes_ / unit), s)
76+
return (format + " %s") % ((base * bytes_ / unit), s)

src/humanize/time.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _date_and_delta(
8888

8989

9090
def naturaldelta(
91-
value: dt.timedelta | int,
91+
value: dt.timedelta | float,
9292
months: bool = True,
9393
minimum_unit: str = "seconds",
9494
) -> str:
@@ -97,7 +97,7 @@ def naturaldelta(
9797
This is similar to `naturaltime`, but does not add tense to the result.
9898
9999
Args:
100-
value (datetime.timedelta or int): A timedelta or a number of seconds.
100+
value (datetime.timedelta, int or float): A timedelta or a number of seconds.
101101
months (bool): If `True`, then a number of months (based on 30.5 days) will be
102102
used for fuzziness between years.
103103
minimum_unit (str): The lowest unit that can be used.
@@ -206,7 +206,7 @@ def naturaldelta(
206206

207207

208208
def naturaltime(
209-
value: dt.datetime | int,
209+
value: dt.datetime | float,
210210
future: bool = False,
211211
months: bool = True,
212212
minimum_unit: str = "seconds",
@@ -217,7 +217,7 @@ def naturaltime(
217217
This is more or less compatible with Django's `naturaltime` filter.
218218
219219
Args:
220-
value (datetime.datetime, int): A `datetime` or a number of seconds.
220+
value (datetime.datetime, int or float): A `datetime` or a number of seconds.
221221
future (bool): Ignored for `datetime`s, where the tense is always figured out
222222
based on the current time. For integers, the return value will be past tense
223223
by default, unless future is `True`.

tests/test_time.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ def test_naturaldelta_nomonths(test_input: dt.timedelta, expected: str) -> None:
9393
[
9494
(0, "a moment"),
9595
(1, "a second"),
96+
(23.5, "23 seconds"),
9697
(30, "30 seconds"),
9798
(dt.timedelta(minutes=1, seconds=30), "a minute"),
9899
(dt.timedelta(minutes=2), "2 minutes"),
@@ -156,6 +157,7 @@ def test_naturaldelta(test_input: int | dt.timedelta, expected: str) -> None:
156157
# regression tests for bugs in post-release humanize
157158
(NOW + dt.timedelta(days=10000), "27 years from now"),
158159
(NOW - dt.timedelta(days=365 + 35), "1 year, 1 month ago"),
160+
(23.5, "23 seconds ago"),
159161
(30, "30 seconds ago"),
160162
(NOW - dt.timedelta(days=365 * 2 + 65), "2 years ago"),
161163
(NOW - dt.timedelta(days=365 + 4), "1 year, 4 days ago"),

0 commit comments

Comments
 (0)