summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-08-30 18:48:55 +0200
committerClaude Paroz <claude@2xlibre.net>2014-08-30 18:51:12 +0200
commit502142179996e32e1c7f334c3d986f21115cfac8 (patch)
tree5a130ec88b99d9e5291523e6e9af3189dcd57167
parent3a297d78169b7d3c6d688cf0e349f4663acc6bad (diff)
Fixed #22820 -- Treated int and long types alike in lazy_number
Thanks kwist for the report and the initial patch.
-rw-r--r--django/utils/translation/__init__.py2
-rw-r--r--tests/i18n/tests.py11
2 files changed, 12 insertions, 1 deletions
diff --git a/django/utils/translation/__init__.py b/django/utils/translation/__init__.py
index e8ef6bd353..505d753268 100644
--- a/django/utils/translation/__init__.py
+++ b/django/utils/translation/__init__.py
@@ -101,7 +101,7 @@ pgettext_lazy = lazy(pgettext, six.text_type)
def lazy_number(func, resultclass, number=None, **kwargs):
- if isinstance(number, int):
+ if isinstance(number, six.integer_types):
kwargs['number'] = number
proxy = lazy(func, resultclass)(**kwargs)
else:
diff --git a/tests/i18n/tests.py b/tests/i18n/tests.py
index aa7602a524..b7d82da12b 100644
--- a/tests/i18n/tests.py
+++ b/tests/i18n/tests.py
@@ -193,6 +193,17 @@ class TranslationTests(TestCase):
with six.assertRaisesRegex(self, KeyError, 'Your dictionary lacks key.*'):
complex_context_deferred % {'name': 'Jim'}
+ @skipUnless(six.PY2, "PY3 doesn't distinct int and long types")
+ def test_ungettext_lazy_long(self):
+ """
+ Regression test for #22820: int and long should be treated alike in ungettext_lazy.
+ """
+ result = ungettext_lazy('%(name)s has %(num)d good result', '%(name)s has %(num)d good results', 4)
+ self.assertEqual(result % {'name': 'Joe', 'num': 4}, "Joe has 4 good results")
+ # Now with a long
+ result = ungettext_lazy('%(name)s has %(num)d good result', '%(name)s has %(num)d good results', long(4))
+ self.assertEqual(result % {'name': 'Joe', 'num': 4}, "Joe has 4 good results")
+
@override_settings(LOCALE_PATHS=extended_locale_paths)
def test_pgettext(self):
trans_real._active = local()