summaryrefslogtreecommitdiff
path: root/django/contrib/humanize
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2019-06-09 12:48:20 -0700
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-06-11 20:34:59 +0200
commit9e38ed0536c7dc598a6c2c1bb774d0a8db3cdddc (patch)
tree735fc06110b76c86b0090a8dd53e2a6a1fcfae4e /django/contrib/humanize
parent175656e166712db019a4704c4031510b9fd6b00a (diff)
Fixed #27486 -- Fixed Python 3.7 DeprecationWarning in intword and filesizeformat filters.
intword and filesizeformat passed floats to ngettext() which is deprecated in Python 3.7. The rationale for this warning is documented in BPO-28692: https://bugs.python.org/issue28692. For filesizeformat, the filesize value is expected to be an int -- it fills %d string formatting placeholders. It was likely coerced to a float to ensure floating point division on Python 2. Python 3 always does floating point division, so coerce to an int instead of a float to fix the warning. For intword, the number may contain a decimal component. In English, a decimal component makes the noun plural. A helper function, round_away_from_one(), was added to convert the float to an integer that is appropriate for ngettext().
Diffstat (limited to 'django/contrib/humanize')
-rw-r--r--django/contrib/humanize/templatetags/humanize.py5
1 files changed, 3 insertions, 2 deletions
diff --git a/django/contrib/humanize/templatetags/humanize.py b/django/contrib/humanize/templatetags/humanize.py
index 194c7e8fbb..31880846f0 100644
--- a/django/contrib/humanize/templatetags/humanize.py
+++ b/django/contrib/humanize/templatetags/humanize.py
@@ -10,7 +10,7 @@ from django.utils.safestring import mark_safe
from django.utils.timezone import is_aware, utc
from django.utils.translation import (
gettext as _, gettext_lazy, ngettext, ngettext_lazy, npgettext_lazy,
- pgettext,
+ pgettext, round_away_from_one,
)
register = template.Library()
@@ -158,7 +158,8 @@ def intword(value):
large_number = 10 ** exponent
if value < large_number * 1000:
new_value = value / large_number
- return _check_for_i18n(new_value, *converters(new_value))
+ rounded_value = round_away_from_one(new_value)
+ return _check_for_i18n(new_value, *converters(rounded_value))
return value