From cde0a3f63700768c16220e06e9c477e602ccfefd Mon Sep 17 00:00:00 2001 From: dansarpong Date: Mon, 2 Oct 2023 16:58:56 +0000 Subject: [PATCH 1/4] Fix plural float error Fixed an error where a float value given in _ngettext generated errors when expecting integer value --- src/humanize/i18n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/humanize/i18n.py b/src/humanize/i18n.py index e391b9f..ea49585 100644 --- a/src/humanize/i18n.py +++ b/src/humanize/i18n.py @@ -123,7 +123,7 @@ def _ngettext(message: str, plural: str, num: int) -> str: Returns: str: Translated text. """ - return get_translation().ngettext(message, plural, num) + return get_translation().ngettext(message, plural, int(num)) def _gettext_noop(message: str) -> str: From f5b82f538c83329f54b72c4c24b06b931193c288 Mon Sep 17 00:00:00 2001 From: dansarpong Date: Tue, 3 Oct 2023 21:20:23 +0000 Subject: [PATCH 2/4] Fix DeprecationWarning error Fixed an error where there was a DeprecationWarning upon using a float, when an integer was expected --- src/humanize/time.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/humanize/time.py b/src/humanize/time.py index 3722678..5acf7d6 100644 --- a/src/humanize/time.py +++ b/src/humanize/time.py @@ -590,7 +590,8 @@ def precisedelta( for unit, fmt in zip(reversed(Unit), fmts): singular_txt, plural_txt, fmt_value = fmt if fmt_value > 0 or (not texts and unit == min_unit): - fmt_txt = _ngettext(singular_txt, plural_txt, fmt_value) + _fmt_value = 2 if fmt_value > 1 and fmt_value < 2 else int(fmt_value) + fmt_txt = _ngettext(singular_txt, plural_txt, _fmt_value) if unit == min_unit and math.modf(fmt_value)[0] > 0: fmt_txt = fmt_txt.replace("%d", format) elif unit == YEARS: From a197516574b124206ad094a235d4122dfb5a2c4f Mon Sep 17 00:00:00 2001 From: Daniel Sarpong Date: Thu, 19 Oct 2023 09:17:57 +0000 Subject: [PATCH 3/4] Update src/humanize/i18n.py Co-authored-by: Hugo van Kemenade --- src/humanize/i18n.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/humanize/i18n.py b/src/humanize/i18n.py index ea49585..e391b9f 100644 --- a/src/humanize/i18n.py +++ b/src/humanize/i18n.py @@ -123,7 +123,7 @@ def _ngettext(message: str, plural: str, num: int) -> str: Returns: str: Translated text. """ - return get_translation().ngettext(message, plural, int(num)) + return get_translation().ngettext(message, plural, num) def _gettext_noop(message: str) -> str: From fe227a6bd97fc1b3d21f45b34267bdaf045828eb Mon Sep 17 00:00:00 2001 From: Daniel Sarpong Date: Thu, 19 Oct 2023 09:18:07 +0000 Subject: [PATCH 4/4] Update src/humanize/time.py Co-authored-by: Hugo van Kemenade --- src/humanize/time.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/humanize/time.py b/src/humanize/time.py index 5acf7d6..52828c1 100644 --- a/src/humanize/time.py +++ b/src/humanize/time.py @@ -590,7 +590,7 @@ def precisedelta( for unit, fmt in zip(reversed(Unit), fmts): singular_txt, plural_txt, fmt_value = fmt if fmt_value > 0 or (not texts and unit == min_unit): - _fmt_value = 2 if fmt_value > 1 and fmt_value < 2 else int(fmt_value) + _fmt_value = 2 if 1 < fmt_value < 2 else int(fmt_value) fmt_txt = _ngettext(singular_txt, plural_txt, _fmt_value) if unit == min_unit and math.modf(fmt_value)[0] > 0: fmt_txt = fmt_txt.replace("%d", format)