Skip to content

Commit c835561

Browse files
StanFromIrelandAA-Turnertomasr8
committed
[3.13] pythongh-138286: Run ruff on Tools/i18n (pythonGH-138287)
(cherry picked from commit 78acd8e) Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Tomas R. <[email protected]>
1 parent 08e9794 commit c835561

File tree

4 files changed

+33
-19
lines changed

4 files changed

+33
-19
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ repos:
1010
name: Run Ruff (lint) on Lib/test/
1111
args: [--exit-non-zero-on-fix]
1212
files: ^Lib/test/
13+
- id: ruff
14+
name: Run Ruff (lint) on Tools/i18n/
15+
args: [--exit-non-zero-on-fix, --config=Tools/i18n/.ruff.toml]
16+
files: ^Tools/i18n/
1317
- id: ruff
1418
name: Run Ruff (lint) on Argument Clinic
1519
args: [--exit-non-zero-on-fix, --config=Tools/clinic/.ruff.toml]

Tools/i18n/.ruff.toml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extend = "../../.ruff.toml" # Inherit the project-wide settings
2+
3+
target-version = "py313"
4+
5+
[lint]
6+
select = [
7+
"F", # pyflakes
8+
"I", # isort
9+
"UP", # pyupgrade
10+
]

Tools/i18n/makelocalealias.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"""
99
import locale
1010
import sys
11+
1112
_locale = locale
1213

1314
# Location of the X11 alias file.
@@ -89,16 +90,15 @@ def parse_glibc_supported(filename):
8990
def pprint(data):
9091
items = sorted(data.items())
9192
for k, v in items:
92-
print(' %-40s%a,' % ('%a:' % k, v))
93+
print(f" {k!a:<40}{v!a},")
9394

9495
def print_differences(data, olddata):
9596
items = sorted(olddata.items())
9697
for k, v in items:
9798
if k not in data:
98-
print('# removed %a' % k)
99+
print(f'# removed {k!a}')
99100
elif olddata[k] != data[k]:
100-
print('# updated %a -> %a to %a' % \
101-
(k, olddata[k], data[k]))
101+
print(f'# updated {k!a} -> {olddata[k]!a} to {data[k]!a}')
102102
# Additions are not mentioned
103103

104104
def optimize(data):
@@ -121,7 +121,7 @@ def check(data):
121121
errors = 0
122122
for k, v in data.items():
123123
if locale.normalize(k) != v:
124-
print('ERROR: %a -> %a != %a' % (k, locale.normalize(k), v),
124+
print(f'ERROR: {k!a} -> {locale.normalize(k)!a} != {v!a}',
125125
file=sys.stderr)
126126
errors += 1
127127
return errors
@@ -131,10 +131,10 @@ def check(data):
131131
parser = argparse.ArgumentParser()
132132
parser.add_argument('--locale-alias', default=LOCALE_ALIAS,
133133
help='location of the X11 alias file '
134-
'(default: %a)' % LOCALE_ALIAS)
134+
f'(default: {LOCALE_ALIAS})')
135135
parser.add_argument('--glibc-supported', default=SUPPORTED,
136136
help='location of the glibc SUPPORTED locales file '
137-
'(default: %a)' % SUPPORTED)
137+
f'(default: {SUPPORTED})')
138138
args = parser.parse_args()
139139

140140
data = locale.locale_alias.copy()

Tools/i18n/msgfmt.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
66
This program converts a textual Uniforum-style message catalog (.po file) into
77
a binary GNU catalog (.mo file). This is essentially the same function as the
8-
GNU msgfmt program, however, it is a simpler implementation. Currently it
9-
does not handle plural forms but it does handle message contexts.
8+
GNU msgfmt program, however, it is a simpler implementation.
109
1110
Usage: msgfmt.py [OPTIONS] filename.po
1211
@@ -25,16 +24,17 @@
2524
Display version information and exit.
2625
"""
2726

28-
import os
29-
import sys
27+
import array
3028
import ast
3129
import getopt
30+
import os
3231
import struct
33-
import array
32+
import sys
3433
from email.parser import HeaderParser
3534

3635
__version__ = "1.2"
3736

37+
3838
MESSAGES = {}
3939

4040

@@ -112,11 +112,12 @@ def make(filename, outfile):
112112
try:
113113
with open(infile, 'rb') as f:
114114
lines = f.readlines()
115-
except IOError as msg:
115+
except OSError as msg:
116116
print(msg, file=sys.stderr)
117117
sys.exit(1)
118118

119119
section = msgctxt = None
120+
msgid = msgstr = b''
120121
fuzzy = 0
121122

122123
# Start off assuming Latin-1, so everything decodes without failure,
@@ -168,7 +169,7 @@ def make(filename, outfile):
168169
# This is a message with plural forms
169170
elif l.startswith('msgid_plural'):
170171
if section != ID:
171-
print('msgid_plural not preceded by msgid on %s:%d' % (infile, lno),
172+
print(f'msgid_plural not preceded by msgid on {infile}:{lno}',
172173
file=sys.stderr)
173174
sys.exit(1)
174175
l = l[12:]
@@ -179,15 +180,15 @@ def make(filename, outfile):
179180
section = STR
180181
if l.startswith('msgstr['):
181182
if not is_plural:
182-
print('plural without msgid_plural on %s:%d' % (infile, lno),
183+
print(f'plural without msgid_plural on {infile}:{lno}',
183184
file=sys.stderr)
184185
sys.exit(1)
185186
l = l.split(']', 1)[1]
186187
if msgstr:
187188
msgstr += b'\0' # Separator of the various plural forms
188189
else:
189190
if is_plural:
190-
print('indexed msgstr required for plural on %s:%d' % (infile, lno),
191+
print(f'indexed msgstr required for plural on {infile}:{lno}',
191192
file=sys.stderr)
192193
sys.exit(1)
193194
l = l[6:]
@@ -203,8 +204,7 @@ def make(filename, outfile):
203204
elif section == STR:
204205
msgstr += l.encode(encoding)
205206
else:
206-
print('Syntax error on %s:%d' % (infile, lno), \
207-
'before:', file=sys.stderr)
207+
print(f'Syntax error on {infile}:{lno} before:', file=sys.stderr)
208208
print(l, file=sys.stderr)
209209
sys.exit(1)
210210
# Add last entry
@@ -217,7 +217,7 @@ def make(filename, outfile):
217217
try:
218218
with open(outfile,"wb") as f:
219219
f.write(output)
220-
except IOError as msg:
220+
except OSError as msg:
221221
print(msg, file=sys.stderr)
222222

223223

0 commit comments

Comments
 (0)