Skip to content

Commit b6fa945

Browse files
miss-islingtonStanFromIrelandAA-Turnertomasr8
authored
[3.14] gh-138286: Run ruff on Tools/i18n (GH-138287) (#138513)
Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Tomas R. <[email protected]>
1 parent 09f1eff commit b6fa945

File tree

5 files changed

+34
-20
lines changed

5 files changed

+34
-20
lines changed

.pre-commit-config.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ repos:
1414
name: Run Ruff (lint) on Tools/build/
1515
args: [--exit-non-zero-on-fix, --config=Tools/build/.ruff.toml]
1616
files: ^Tools/build/
17+
- id: ruff
18+
name: Run Ruff (lint) on Tools/i18n/
19+
args: [--exit-non-zero-on-fix, --config=Tools/i18n/.ruff.toml]
20+
files: ^Tools/i18n/
1721
- id: ruff
1822
name: Run Ruff (lint) on Argument Clinic
1923
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: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,14 @@
2525
Display version information and exit.
2626
"""
2727

28-
import os
29-
import sys
28+
import array
3029
import ast
30+
import codecs
3131
import getopt
32+
import os
3233
import struct
33-
import array
34+
import sys
3435
from email.parser import HeaderParser
35-
import codecs
3636

3737
__version__ = "1.2"
3838

@@ -114,7 +114,7 @@ def make(filename, outfile):
114114
try:
115115
with open(infile, 'rb') as f:
116116
lines = f.readlines()
117-
except IOError as msg:
117+
except OSError as msg:
118118
print(msg, file=sys.stderr)
119119
sys.exit(1)
120120

@@ -127,6 +127,7 @@ def make(filename, outfile):
127127
sys.exit(1)
128128

129129
section = msgctxt = None
130+
msgid = msgstr = b''
130131
fuzzy = 0
131132

132133
# Start off assuming Latin-1, so everything decodes without failure,
@@ -178,7 +179,7 @@ def make(filename, outfile):
178179
# This is a message with plural forms
179180
elif l.startswith('msgid_plural'):
180181
if section != ID:
181-
print('msgid_plural not preceded by msgid on %s:%d' % (infile, lno),
182+
print(f'msgid_plural not preceded by msgid on {infile}:{lno}',
182183
file=sys.stderr)
183184
sys.exit(1)
184185
l = l[12:]
@@ -189,15 +190,15 @@ def make(filename, outfile):
189190
section = STR
190191
if l.startswith('msgstr['):
191192
if not is_plural:
192-
print('plural without msgid_plural on %s:%d' % (infile, lno),
193+
print(f'plural without msgid_plural on {infile}:{lno}',
193194
file=sys.stderr)
194195
sys.exit(1)
195196
l = l.split(']', 1)[1]
196197
if msgstr:
197198
msgstr += b'\0' # Separator of the various plural forms
198199
else:
199200
if is_plural:
200-
print('indexed msgstr required for plural on %s:%d' % (infile, lno),
201+
print(f'indexed msgstr required for plural on {infile}:{lno}',
201202
file=sys.stderr)
202203
sys.exit(1)
203204
l = l[6:]
@@ -213,8 +214,7 @@ def make(filename, outfile):
213214
elif section == STR:
214215
msgstr += l.encode(encoding)
215216
else:
216-
print('Syntax error on %s:%d' % (infile, lno), \
217-
'before:', file=sys.stderr)
217+
print(f'Syntax error on {infile}:{lno} before:', file=sys.stderr)
218218
print(l, file=sys.stderr)
219219
sys.exit(1)
220220
# Add last entry
@@ -227,7 +227,7 @@ def make(filename, outfile):
227227
try:
228228
with open(outfile,"wb") as f:
229229
f.write(output)
230-
except IOError as msg:
230+
except OSError as msg:
231231
print(msg, file=sys.stderr)
232232

233233

Tools/i18n/pygettext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ def make_escapes(pass_nonascii):
193193
escape = escape_ascii
194194
else:
195195
escape = escape_nonascii
196-
escapes = [r"\%03o" % i for i in range(256)]
196+
escapes = [fr"\{i:03o}" for i in range(256)]
197197
for i in range(32, 127):
198198
escapes[i] = chr(i)
199199
escapes[ord('\\')] = r'\\'
@@ -796,7 +796,7 @@ class Options:
796796
try:
797797
with open(options.excludefilename) as fp:
798798
options.toexclude = fp.readlines()
799-
except IOError:
799+
except OSError:
800800
print(f"Can't read --exclude-file: {options.excludefilename}",
801801
file=sys.stderr)
802802
sys.exit(1)

0 commit comments

Comments
 (0)