Skip to content

Commit bf7b94f

Browse files
VoltrexKeyvatargos
authored andcommitted
tools: refactor checkimports.py
- Use f-strings for formatting. - Use raw strings for regexes alongside f-strings. - Use a generator. - Remove unnecessary `else` clause. PR-URL: #50011 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Christian Clauss <cclauss@me.com>
1 parent e5c7dca commit bf7b94f

1 file changed

Lines changed: 7 additions & 9 deletions

File tree

‎tools/checkimports.py‎

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
importitertools
99

1010
defdo_exist(file_name, lines, imported):
11-
ifnotany(notre.match('using \w+::{0};'.format(imported), line) and
12-
re.search('\\b{0}\\b'.format(imported), line) forlineinlines):
13-
print('File "{0}" does not use "{1}"'.format(file_name, imported))
11+
ifnotany(notre.match(fr'using \w+::{imported};', line) and
12+
re.search(fr'\b{imported}\b', line) forlineinlines):
13+
print(f'File "{file_name}" does not use "{imported}"')
1414
returnFalse
1515
returnTrue
1616

@@ -27,18 +27,16 @@ def is_valid(file_name):
2727
usings.append(matches.group(1))
2828
importeds.append(matches.group(2))
2929

30-
valid=all([do_exist(file_name, lines, imported) forimportedinimporteds])
30+
valid=all(do_exist(file_name, lines, imported) forimportedinimporteds)
3131

3232
sorted_usings=sorted(usings, key=lambdax: x.lower())
3333
ifsorted_usings!=usings:
34-
print("using statements aren't sorted in '{0}'.".format(file_name))
34+
print(f"using statements aren't sorted in '{file_name}'.")
3535
fornum, actual, expectedinzip(line_numbers, usings, sorted_usings):
3636
ifactual!=expected:
37-
print('\tLine {0}: Actual: {1}, Expected: {2}'
38-
.format(num, actual, expected))
37+
print(f'\tLine {num}: Actual: {actual}, Expected: {expected}')
3938
returnFalse
40-
else:
41-
returnvalid
39+
returnvalid
4240

4341
if__name__=='__main__':
4442
iflen(sys.argv) >1:

0 commit comments

Comments
 (0)