Skip to content

Commit 9a3fcda

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent a23fa42 commit 9a3fcda

2 files changed

Lines changed: 10 additions & 15 deletions

File tree

src/humanize/time.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,13 @@ def naturaldelta(
147147
# When a context is provided, use pgettext/npgettext so that translators
148148
# can supply case-aware forms (e.g. German dative for "ago"/"from now").
149149
if context is not None:
150+
150151
def _ng(singular: str, plural: str, num: int) -> str:
151152
return _npgettext(context, singular, plural, num)
152153

153154
def _g(message: str) -> str:
154155
return _pgettext(context, message)
156+
155157
else:
156158
_ng = _ngettext
157159
_g = _
@@ -256,10 +258,7 @@ def _g(message: str) -> str:
256258
years += 1
257259
return _ng("%d year", "%d years", years) % years
258260

259-
return (
260-
_ng("1 year, %d month", "1 year, %d months", num_months)
261-
% num_months
262-
)
261+
return _ng("1 year, %d month", "1 year, %d months", num_months) % num_months
263262

264263
return _ng("1 year, %d day", "1 year, %d days", days) % days
265264

tests/test_time.py

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -866,9 +866,7 @@ def test_rounding_by_fmt(fmt: str, value: float, expected: float) -> None:
866866
(3600 * 24 * 365, "a year"),
867867
],
868868
)
869-
def test_naturaldelta_context_returns_same_english(
870-
seconds: int, expected: str
871-
) -> None:
869+
def test_naturaldelta_context_returns_same_english(seconds: int, expected: str) -> None:
872870
"""When no translation is active, the context parameter must not change output."""
873871
assert humanize.naturaldelta(seconds, context="naturaltime-past") == expected
874872
assert humanize.naturaldelta(seconds, context="naturaltime-future") == expected
@@ -878,8 +876,10 @@ def test_naturaldelta_context_calls_npgettext() -> None:
878876
"""Verify that pgettext/npgettext are invoked when a context is supplied."""
879877
from unittest.mock import patch
880878

881-
with patch("humanize.time._npgettext", wraps=time._npgettext) as mock_np, \
882-
patch("humanize.time._pgettext", wraps=time._pgettext) as mock_p:
879+
with (
880+
patch("humanize.time._npgettext", wraps=time._npgettext) as mock_np,
881+
patch("humanize.time._pgettext", wraps=time._pgettext) as mock_p,
882+
):
883883
humanize.naturaldelta(30, context="naturaltime-past")
884884
# 30 seconds uses npgettext
885885
mock_np.assert_called_once_with(
@@ -904,12 +904,8 @@ def test_naturaltime_passes_context_to_naturaldelta() -> None:
904904

905905
with patch("humanize.time._npgettext", wraps=time._npgettext) as mock_np:
906906
humanize.naturaltime(past)
907-
mock_np.assert_called_with(
908-
"naturaltime-past", "%d second", "%d seconds", 30
909-
)
907+
mock_np.assert_called_with("naturaltime-past", "%d second", "%d seconds", 30)
910908

911909
mock_np.reset_mock()
912910
humanize.naturaltime(future)
913-
mock_np.assert_called_with(
914-
"naturaltime-future", "%d second", "%d seconds", 30
915-
)
911+
mock_np.assert_called_with("naturaltime-future", "%d second", "%d seconds", 30)

0 commit comments

Comments
 (0)