homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

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 <1479135819.38.0.632535497954.issue28563@psf.upfronthosting.co.za>
In-reply-to
Content
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']
History
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: <1479135819.38.0.632535497954.issue28563@psf.upfronthosting.co.za>
2016年11月14日 15:03:39Tim.Grahamlinkissue28563 messages
2016年11月14日 15:03:38Tim.Grahamcreate

AltStyle によって変換されたページ (->オリジナル) /