mirror of
https://github.com/django/django.git
synced 2025-11-07 07:15:35 +00:00
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().
This commit is contained in:
committed by
Mariusz Felisiak
parent
175656e166
commit
9e38ed0536
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user