Tim Graham added the comment:

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/test_filesizeformat.py",
 line 28, in test_localized_formats
    self.assertEqual(filesizeformat(1023), '1023\xa0Bytes')
  File "/home/tim/code/django/django/template/defaultfilters.py", line 895, in 
filesizeformat
    value = ungettext("%(size)d byte", "%(size)d bytes", bytes_) % {'size': 
bytes_}
  File "/home/tim/code/django/django/utils/translation/__init__.py", line 91, 
in ungettext
    return _trans.ungettext(singular, plural, number)
  File "/home/tim/code/django/django/utils/translation/trans_real.py", line 
385, in ngettext
    return do_ntranslate(singular, plural, number, 'ngettext')
  File "/home/tim/code/django/django/utils/translation/trans_real.py", line 
372, in do_ntranslate
    return getattr(t, translation_function)(singular, plural, number)
  File "/home/tim/code/cpython/Lib/gettext.py", 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/gettext.py b/Lib/gettext.py
index 7032efa..2076a3f 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -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']

----------
nosy: +Tim.Graham

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue28563>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to