From f13ae569d06009bf7e04e89a31202394ef3527d9 Mon Sep 17 00:00:00 2001 From: Teal Dulcet Date: Sun, 12 Jan 2025 07:10:31 -0800 Subject: [PATCH] Fixed SIM115 (open-file-with-context-handler): Use a context manager for opening files --- management/mail_log.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/management/mail_log.py b/management/mail_log.py index 34bc7630..a641ef7d 100755 --- a/management/mail_log.py +++ b/management/mail_log.py @@ -72,9 +72,9 @@ def scan_files(collector): if not os.path.exists(fn): continue if fn[-3:] == '.gz': - tmp_file = tempfile.NamedTemporaryFile() - with gzip.open(fn, 'rb') as f: - shutil.copyfileobj(f, tmp_file) + with tempfile.NamedTemporaryFile(delete=False) as tmp_file: + with gzip.open(fn, 'rb') as f: + shutil.copyfileobj(f, tmp_file) if VERBOSE: print("Processing file", fn, "...")