Skip to content

Commit 61f07d8

Browse files
StanFromIrelandAA-Turnertomasr8
authored
[3.13] pythongh-138286: Run ruff on Tools/i18n (pythonGH-138287) (python#138524)
* [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]> * Commit * Commit --------- Co-authored-by: Adam Turner <[email protected]> Co-authored-by: Tomas R. <[email protected]>
1 parent f0756f8 commit 61f07d8

File tree

5 files changed

+34
-19
lines changed

5 files changed

+34
-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: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,17 @@
2525
Display version information and exit.
2626
"""
2727

28-
import os
29-
import sys
28+
import array
3029
import ast
3130
import getopt
31+
import os
3232
import struct
33-
import array
33+
import sys
3434
from email.parser import HeaderParser
3535

3636
__version__ = "1.2"
3737

38+
3839
MESSAGES = {}
3940

4041

@@ -112,11 +113,12 @@ def make(filename, outfile):
112113
try:
113114
with open(infile, 'rb') as f:
114115
lines = f.readlines()
115-
except IOError as msg:
116+
except OSError as msg:
116117
print(msg, file=sys.stderr)
117118
sys.exit(1)
118119

119120
section = msgctxt = None
121+
msgid = msgstr = b''
120122
fuzzy = 0
121123

122124
# Start off assuming Latin-1, so everything decodes without failure,
@@ -168,7 +170,7 @@ def make(filename, outfile):
168170
# This is a message with plural forms
169171
elif l.startswith('msgid_plural'):
170172
if section != ID:
171-
print('msgid_plural not preceded by msgid on %s:%d' % (infile, lno),
173+
print(f'msgid_plural not preceded by msgid on {infile}:{lno}',
172174
file=sys.stderr)
173175
sys.exit(1)
174176
l = l[12:]
@@ -179,15 +181,15 @@ def make(filename, outfile):
179181
section = STR
180182
if l.startswith('msgstr['):
181183
if not is_plural:
182-
print('plural without msgid_plural on %s:%d' % (infile, lno),
184+
print(f'plural without msgid_plural on {infile}:{lno}',
183185
file=sys.stderr)
184186
sys.exit(1)
185187
l = l.split(']', 1)[1]
186188
if msgstr:
187189
msgstr += b'\0' # Separator of the various plural forms
188190
else:
189191
if is_plural:
190-
print('indexed msgstr required for plural on %s:%d' % (infile, lno),
192+
print(f'indexed msgstr required for plural on {infile}:{lno}',
191193
file=sys.stderr)
192194
sys.exit(1)
193195
l = l[6:]
@@ -203,8 +205,7 @@ def make(filename, outfile):
203205
elif section == STR:
204206
msgstr += l.encode(encoding)
205207
else:
206-
print('Syntax error on %s:%d' % (infile, lno), \
207-
'before:', file=sys.stderr)
208+
print(f'Syntax error on {infile}:{lno} before:', file=sys.stderr)
208209
print(l, file=sys.stderr)
209210
sys.exit(1)
210211
# Add last entry
@@ -217,7 +218,7 @@ def make(filename, outfile):
217218
try:
218219
with open(outfile,"wb") as f:
219220
f.write(output)
220-
except IOError as msg:
221+
except OSError as msg:
221222
print(msg, file=sys.stderr)
222223

223224

Tools/i18n/pygettext.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ def make_escapes(pass_nonascii):
214214
else:
215215
mod = 256
216216
escape = escape_nonascii
217-
escapes = [r"\%03o" % i for i in range(mod)]
217+
escapes = [fr"\{i:03o}" for i in range(mod)]
218218
for i in range(32, 127):
219219
escapes[i] = chr(i)
220220
escapes[ord('\\')] = r'\\'
@@ -620,7 +620,7 @@ class Options:
620620
try:
621621
with open(options.excludefilename) as fp:
622622
options.toexclude = fp.readlines()
623-
except IOError:
623+
except OSError:
624624
print(_(
625625
"Can't read --exclude-file: %s") % options.excludefilename, file=sys.stderr)
626626
sys.exit(1)

0 commit comments

Comments
 (0)