Thanks to visit codestin.com
Credit goes to github.com

Skip to content

bpo-28692: Using non-integer value for selecting a plural form in get… #507

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Doc/whatsnew/3.7.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=======
Expand Down
4 changes: 4 additions & 0 deletions Lib/gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 6 additions & 3 deletions Lib/test/test_gettext.py
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,12 @@ def test_plural_number(self):
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, [])
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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().

Expand Down