Skip to content

Commit a91dd1e

Browse files
committed
use native tenary condition
1 parent 5793e6f commit a91dd1e

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

Lib/gettext.py

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,6 @@
5858
_default_localedir = os.path.join(sys.prefix, 'share', 'locale')
5959

6060

61-
def test(condition, true, false):
62-
"""
63-
Implements the C expression:
64-
65-
condition ? true : false
66-
67-
Required to correctly interpret plural forms.
68-
"""
69-
if condition:
70-
return true
71-
else:
72-
return false
73-
74-
7561
def c2py(plural):
7662
"""Gets a C expression as used in PO files for plural forms and returns a
7763
Python lambda function that implements an equivalent expression.
@@ -99,8 +85,8 @@ def c2py(plural):
9985
# "a?b:c" to "test(a,b,c)".
10086
expr = re.compile(r'(.*?)\?(.*?):(.*)')
10187
def repl(x):
102-
return "test(%s, %s, %s)" % (x.group(1), x.group(2),
103-
expr.sub(repl, x.group(3)))
88+
return "(%s if %s else %s)" % (x.group(2), x.group(1),
89+
expr.sub(repl, x.group(3)))
10490

10591
# Code to transform the plural expression, taking care of parentheses
10692
stack = ['']

0 commit comments

Comments
 (0)