Skip to content

Commit 8ee1c44

Browse files
committed
Refactor file opening
1 parent 66c0c67 commit 8ee1c44

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

llvm/utils/lit/lit/reports.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,26 +24,25 @@ def __init__(self, output_file):
2424

2525
def write_results(self, tests, elapsed):
2626
if self.use_unique_output_file_name:
27-
file = None
27+
report_file = None
2828
filepath = self.output_file
2929
attempt = 0
30-
while file is None:
30+
while report_file is None:
3131
try:
32-
file = open(filepath, "x")
32+
report_file = open(filepath, "x")
3333
except FileExistsError:
3434
attempt += 1
3535
# If there is an extension insert before that because most
3636
# glob patterns for these will be '*.extension'. Otherwise
3737
# add to the end of the path.
3838
path, ext = os.path.splitext(self.output_file)
3939
filepath = path + f".{attempt}" + ext
40-
41-
with file:
42-
self._write_results_to_file(tests, elapsed, file)
4340
else:
4441
# Overwrite if the results already exist.
45-
with open(self.output_file, "w") as file:
46-
self._write_results_to_file(tests, elapsed, file)
42+
report_file = open(self.output_file, "w")
43+
44+
with report_file:
45+
self._write_results_to_file(tests, elapsed, report_file)
4746

4847
@abc.abstractmethod
4948
def _write_results_to_file(self, tests, elapsed, file):

0 commit comments

Comments
 (0)