Skip to content

Commit 156c369

Browse files
author
Thomas Preud'homme
committed
[LNT, NFC] Open tmp file in a context
Summary: Simplify opening tmp file by using a context to have automatic closing of the file descriptor. Reviewers: cmatthews, hubert.reinterpretcast, leandron, PrzemekWirkus, kristof.beyls Reviewed By: PrzemekWirkus Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D71058
1 parent 81977a8 commit 156c369

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

lnt/util/ImportData.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,8 @@ def import_from_string(config, db_name, db, session, ts_name, data,
338338
prefix = utcnow.strftime("data-%Y-%m-%d_%H-%M-%S")
339339
fd, path = tempfile.mkstemp(prefix=prefix, suffix='.json',
340340
dir=str(tmpdir), text=True)
341-
fp = os.fdopen(fd, "w")
342-
fp.write(data)
343-
fp.close()
341+
with os.fdopen(fd, "w") as fp:
342+
fp.write(data)
344343

345344
# Import the data.
346345
#

0 commit comments

Comments
 (0)