diff --git a/.ruff-excludes.toml b/.ruff-excludes.toml index 80b204f5c4d..ec51690e76b 100644 --- a/.ruff-excludes.toml +++ b/.ruff-excludes.toml @@ -568,10 +568,6 @@ "UP036", # https://docs.astral.sh/ruff/rules/outdated-version-block "UP038", # https://docs.astral.sh/ruff/rules/non-pep604-isinstance ] -"./scripts/logging/dictionary/log_parser.py" = [ - "SIM115", # https://docs.astral.sh/ruff/rules/open-file-with-context-handler - "UP015", # https://docs.astral.sh/ruff/rules/redundant-open-modes -] "./scripts/make_bugs_pickle.py" = [ "UP006", # https://docs.astral.sh/ruff/rules/non-pep585-annotation "UP035", # https://docs.astral.sh/ruff/rules/deprecated-import diff --git a/scripts/logging/dictionary/log_parser.py b/scripts/logging/dictionary/log_parser.py index 3d4d8253faf..8d640e8c38c 100755 --- a/scripts/logging/dictionary/log_parser.py +++ b/scripts/logging/dictionary/log_parser.py @@ -57,7 +57,7 @@ def read_log_file(args): else: hexdata = '' - with open(args.logfile, "r", encoding="iso-8859-1") as hexfile: + with open(args.logfile, encoding="iso-8859-1") as hexfile: for line in hexfile.readlines(): hexdata += line.strip() @@ -90,14 +90,11 @@ def read_log_file(args): logdata = binascii.unhexlify(hexdata[:idx]) else: - logfile = open(args.logfile, "rb") - if not logfile: - logger.error("ERROR: Cannot open binary log data file: %s, exiting...", args.logfile) - sys.exit(1) - - logdata = logfile.read() - - logfile.close() + with open(args.logfile, "rb") as logfile: + if not logfile: + logger.error(f"ERROR: Cannot open binary log data file: {args.logfile}, exiting...") + sys.exit(1) + logdata = logfile.read() return logdata