summaryrefslogtreecommitdiff
path: root/django/template
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/template
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/template')
-rw-r--r--django/template/defaultfilters.py2
1 files changed, 1 insertions, 1 deletions
diff --git a/django/template/defaultfilters.py b/django/template/defaultfilters.py
index d8fb0a5396..174d2a092d 100644
--- a/django/template/defaultfilters.py
+++ b/django/template/defaultfilters.py
@@ -812,7 +812,7 @@ def filesizeformat(bytes_):
102 bytes, etc.).
"""
try:
- bytes_ = float(bytes_)
+ bytes_ = int(bytes_)
except (TypeError, ValueError, UnicodeDecodeError):
value = ngettext("%(size)d byte", "%(size)d bytes", 0) % {'size': 0}
return avoid_wrapping(value)