[PATCH] D71058: [LNT, NFC] Open tmp file in a context

Thomas Preud'homme via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 5 05:07:48 PST 2019


thopre created this revision.
thopre added reviewers: cmatthews, hubert.reinterpretcast, leandron, PrzemekWirkus, kristof.beyls.

Simplify opening tmp file by using a context to have automatic closing
of the file descriptor.


https://reviews.llvm.org/D71058

Files:
  lnt/util/ImportData.py


Index: lnt/util/ImportData.py
===================================================================
--- lnt/util/ImportData.py
+++ lnt/util/ImportData.py
@@ -337,9 +337,8 @@
     prefix = utcnow.strftime("data-%Y-%m-%d_%H-%M-%S")
     fd, path = tempfile.mkstemp(prefix=prefix, suffix='.json',
                                 dir=str(tmpdir), text=True)
-    fp = os.fdopen(fd, "w")
-    fp.write(data)
-    fp.close()
+    with os.fdopen(fd, "w") as fp:
+        fp.write(data)
 
     # Import the data.
     #


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D71058.232318.patch
Type: text/x-patch
Size: 511 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191205/4fe38881/attachment.bin>


More information about the llvm-commits mailing list