Commit d839c756 authored by Claude Paroz's avatar Claude Paroz
Browse files

[1.7.x] Fixed #22820 -- Treated int and long types alike in lazy_number

Thanks kwist for the report and the initial patch.
Backport of 50214217 from master.
parent 3297f9e1
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -100,7 +100,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:
+11 −0
Original line number Diff line number Diff line
@@ -154,6 +154,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()