From: Serhiy Storchaka Date: Sun, 12 Mar 2017 11:15:01 +0000 (+0200) Subject: bpo-28692: Deprecate using non-integer value for selecting a plural form in gettext... X-Git-Tag: v3.7.0a1~1142 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f6595983e08fe20cf06a2535d74d912c6dbb044f;p=python bpo-28692: Deprecate using non-integer value for selecting a plural form in gettext. (#507) --- diff --git a/Doc/whatsnew/3.7.rst b/Doc/whatsnew/3.7.rst index 71ae10bbb1..4f84e6df28 100644 --- a/Doc/whatsnew/3.7.rst +++ b/Doc/whatsnew/3.7.rst @@ -180,6 +180,10 @@ Deprecated both deprecated in Python 3.4 now emit :exc:`DeprecationWarning`. (Contributed by Matthias Bussonnier in :issue:`29576`) +- Using non-integer value for selecting a plural form in :mod:`gettext` is + now deprecated. It never correctly worked. + (Contributed by Serhiy Storchaka in :issue:`28692`.) + Removed ======= diff --git a/Lib/gettext.py b/Lib/gettext.py index 57d2c74982..aa1d55561f 100644 --- a/Lib/gettext.py +++ b/Lib/gettext.py @@ -164,6 +164,10 @@ def _as_int(n): except TypeError: raise TypeError('Plural value must be an integer, got %s' % (n.__class__.__name__,)) from None + import warnings + warnings.warn('Plural value must be an integer, got %s' % + (n.__class__.__name__,), + DeprecationWarning, 4) return n def c2py(plural): diff --git a/Lib/test/test_gettext.py b/Lib/test/test_gettext.py index a852443e68..7bfe747d3b 100644 --- a/Lib/test/test_gettext.py +++ b/Lib/test/test_gettext.py @@ -443,9 +443,12 @@ class PluralFormsTestCase(GettextBaseTest): f = gettext.c2py('n != 1') self.assertEqual(f(1), 0) self.assertEqual(f(2), 1) - self.assertEqual(f(1.0), 0) - self.assertEqual(f(2.0), 1) - self.assertEqual(f(1.1), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(f(1.0), 0) + with self.assertWarns(DeprecationWarning): + self.assertEqual(f(2.0), 1) + with self.assertWarns(DeprecationWarning): + self.assertEqual(f(1.1), 1) self.assertRaises(TypeError, f, '2') self.assertRaises(TypeError, f, b'2') self.assertRaises(TypeError, f, []) diff --git a/Misc/NEWS b/Misc/NEWS index 694bc34441..03ca0dce38 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -270,6 +270,9 @@ Extension Modules Library ------- +- bpo-28692: Using non-integer value for selecting a plural form in gettext is + now deprecated. + - bpo-26121: Use C library implementation for math functions: tgamma(), lgamma(), erf() and erfc().