Skip to content

Commit 5dff0be

Browse files
committed
scripts/visualize-builds.py: Satisfy ruff and pylint
scripts/visualize-builds.py:169:23: SIM115 Use a context manager for opening files | 167 | output_file = None 168 | if args.output: 169 | output_file = open(args.output, "w", newline="") | ^^^^ SIM115 170 | 171 | try: | scripts/visualize-builds.py:176:9: PLR5501 [*] Use `elif` instead of `else` then `if`, to reduce indentation | 174 | elif args.format == "pretty": 175 | output_pretty_table(days, output_file) 176 | / else: # regular table 177 | | if ( | |____________^ PLR5501 178 | output_file 179 | ): # evil hack so I don't have to rewrite visualize_data() prints | = help: Convert to `elif` Found 2 errors. ************* Module visualize-builds scripts/visualize-builds.py:169:22: W1514: Using open without explicitly specifying an encoding (unspecified-encoding) scripts/visualize-builds.py:169:22: R1732: Consider using 'with' for resource-allocating operations (consider-using-with) Signed-off-by: Nathan Chancellor <[email protected]>
1 parent e7d52ef commit 5dff0be

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

scripts/visualize-builds.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -164,23 +164,24 @@ def main():
164164

165165
output_file = None
166166
if args.output:
167-
output_file = open(args.output, "w", newline="")
167+
# pylint: disable-next=consider-using-with
168+
output_file = open( # noqa: SIM115
169+
args.output, "w", encoding="utf-8", newline="")
168170

169171
try:
170172
if args.format == "csv":
171173
output_csv(days, output_file)
172174
elif args.format == "pretty":
173175
output_pretty_table(days, output_file)
174-
else: # regular table
175-
if (
176-
output_file
177-
): # evil hack so I don't have to rewrite visualize_data() prints
178-
original_stdout = sys.stdout
179-
sys.stdout = output_file
180-
visualize_data(days)
181-
sys.stdout = original_stdout
182-
else:
183-
visualize_data(days)
176+
# regular table
177+
elif output_file:
178+
# evil hack so I don't have to rewrite visualize_data() prints
179+
original_stdout = sys.stdout
180+
sys.stdout = output_file
181+
visualize_data(days)
182+
sys.stdout = original_stdout
183+
else:
184+
visualize_data(days)
184185
finally:
185186
if output_file:
186187
output_file.close()

0 commit comments

Comments
 (0)