Skip to content

Commit 35b160e

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 <[email protected]> Reviewed-By: Christian Clauss <[email protected]>
1 parent 33470d9 commit 35b160e

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

tools/checkimports.py

+7-9
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
import itertools
99

1010
def do_exist(file_name, lines, imported):
11-
if not any(not re.match('using \w+::{0};'.format(imported), line) and
12-
re.search('\\b{0}\\b'.format(imported), line) for line in lines):
13-
print('File "{0}" does not use "{1}"'.format(file_name, imported))
11+
if not any(not re.match(fr'using \w+::{imported};', line) and
12+
re.search(fr'\b{imported}\b', line) for line in lines):
13+
print(f'File "{file_name}" does not use "{imported}"')
1414
return False
1515
return True
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) for imported in importeds])
30+
valid = all(do_exist(file_name, lines, imported) for imported in importeds)
3131

3232
sorted_usings = sorted(usings, key=lambda x: x.lower())
3333
if sorted_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
for num, actual, expected in zip(line_numbers, usings, sorted_usings):
3636
if actual != expected:
37-
print('\tLine {0}: Actual: {1}, Expected: {2}'
38-
.format(num, actual, expected))
37+
print(f'\tLine {num}: Actual: {actual}, Expected: {expected}')
3938
return False
40-
else:
41-
return valid
39+
return valid
4240

4341
if __name__ == '__main__':
4442
if len(sys.argv) > 1:

0 commit comments

Comments
 (0)