Author Tim.Graham
Recipients Carl Ekerot, Tim.Graham, christian.heimes, loewis, python-dev, serhiy.storchaka, xiang.zhang
Date 2016-11-14.15:03:38
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Hi, this broke a couple tests with Django because it's passing number as a float rather than an integer. For example:

ERROR: test_localized_formats (template_tests.filter_tests.test_filesizeformat.FunctionTests)
Traceback (most recent call last):
  File "/home/tim/code/django/tests/template_tests/filter_tests/", line 28, in test_localized_formats
    self.assertEqual(filesizeformat(1023), '1023\xa0Bytes')
  File "/home/tim/code/django/django/template/", line 895, in filesizeformat
    value = ungettext("%(size)d byte", "%(size)d bytes", bytes_) % {'size': bytes_}
  File "/home/tim/code/django/django/utils/translation/", line 91, in ungettext
    return _trans.ungettext(singular, plural, number)
  File "/home/tim/code/django/django/utils/translation/", line 385, in ngettext
    return do_ntranslate(singular, plural, number, 'ngettext')
  File "/home/tim/code/django/django/utils/translation/", line 372, in do_ntranslate
    return getattr(t, translation_function)(singular, plural, number)
  File "/home/tim/code/cpython/Lib/", line 441, in ngettext
    tmsg = self._catalog[(msgid1, self.plural(n))]
  File "<string>", line 4, in func
ValueError: Plural value must be an integer, got 1023.0.

Can you advise if this patch could be adapted or if Django should adapt?

By the way, I used this patch to get a more useful error message:

diff --git a/Lib/ b/Lib/
index 7032efa..2076a3f 100644
--- a/Lib/
+++ b/Lib/
@@ -185,7 +185,7 @@ def c2py(plural):
         exec('''if True:
             def func(n):
                 if not isinstance(n, int):
-                    raise ValueError('Plural value must be an integer.')
+                    raise ValueError('Plural value must be an integer, got %%s.
                 return int(%s)
             ''' % result, ns)
         return ns['func']
Date User Action Args
2016-11-14 15:03:39Tim.Grahamsetrecipients: + Tim.Graham, loewis, christian.heimes, python-dev, serhiy.storchaka, xiang.zhang, Carl Ekerot
2016-11-14 15:03:39Tim.Grahamsetmessageid: <>
2016-11-14 15:03:39Tim.Grahamlinkissue28563 messages
2016-11-14 15:03:38Tim.Grahamcreate