[PR #9579/0de39a6f backport][stable-10] use open() as context manager (#9596)

use open() as context manager (#9579)

* use open() as context manager

* add changelog frag

(cherry picked from commit 0de39a6f47)

Co-authored-by: Alexei Znamensky <103110+russoz@users.noreply.github.com>
This commit is contained in:
patchback[bot] 2025-01-21 21:04:28 +01:00 committed by GitHub
commit e9b58cfc09
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 72 additions and 102 deletions

View file

@ -588,11 +588,8 @@ def read_record(file_path, default=None):
Reads the first line of a file and returns it.
"""
try:
f = open(file_path, 'r')
try:
with open(file_path, 'r') as f:
return f.readline().strip()
finally:
f.close()
except IOError:
return default