summaryrefslogtreecommitdiffstats
path: root/Lib/gettext.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2023-10-14 06:07:02 (GMT)
committerGitHub <noreply@github.com>2023-10-14 06:07:02 (GMT)
commit38bd2c520a2df7904e32093da2166eec2c039802 (patch)
tree38c31ad1a4b3ec189658ccc9023520df6912f88e /Lib/gettext.py
parent45cfabb8429b5ecee78ca60c1ca8f7f5820afc5c (diff)
downloadcpython-38bd2c520a2df7904e32093da2166eec2c039802.zip
cpython-38bd2c520a2df7904e32093da2166eec2c039802.tar.gz
cpython-38bd2c520a2df7904e32093da2166eec2c039802.tar.bz2
gh-88434: Emit deprecation warnings for non-integer numbers in gettext if translation not found (GH-110574)
Diffstat (limited to 'Lib/gettext.py')
-rw-r--r--Lib/gettext.py11
1 files changed, 11 insertions, 0 deletions
diff --git a/Lib/gettext.py b/Lib/gettext.py
index e84765b..62cff81 100644
--- a/Lib/gettext.py
+++ b/Lib/gettext.py
@@ -171,6 +171,13 @@ def _as_int(n):
except TypeError:
raise TypeError('Plural value must be an integer, got %s' %
(n.__class__.__name__,)) from None
+ return _as_int2(n)
+
+def _as_int2(n):
+ try:
+ return operator.index(n)
+ except TypeError:
+ pass
import warnings
frame = sys._getframe(1)
@@ -288,6 +295,7 @@ class NullTranslations:
def ngettext(self, msgid1, msgid2, n):
if self._fallback:
return self._fallback.ngettext(msgid1, msgid2, n)
+ n = _as_int2(n)
if n == 1:
return msgid1
else:
@@ -301,6 +309,7 @@ class NullTranslations:
def npgettext(self, context, msgid1, msgid2, n):
if self._fallback:
return self._fallback.npgettext(context, msgid1, msgid2, n)
+ n = _as_int2(n)
if n == 1:
return msgid1
else:
@@ -587,6 +596,7 @@ def dngettext(domain, msgid1, msgid2, n):
try:
t = translation(domain, _localedirs.get(domain, None))
except OSError:
+ n = _as_int2(n)
if n == 1:
return msgid1
else:
@@ -606,6 +616,7 @@ def dnpgettext(domain, context, msgid1, msgid2, n):
try:
t = translation(domain, _localedirs.get(domain, None))
except OSError:
+ n = _as_int2(n)
if n == 1:
return msgid1
else: