bundlerepo: use context manager for file I/O in _writetempbundle
authorBryan O'Sullivan <bryano@fb.com>
Tue, 12 Jan 2016 14:48:27 -0800
changeset 27776 6fe2da48a6dd
parent 27775 3ea35a0769fe
child 27777 47ac135113ec
bundlerepo: use context manager for file I/O in _writetempbundle
mercurial/bundlerepo.py
--- a/mercurial/bundlerepo.py	Tue Jan 12 14:47:21 2016 -0800
+++ b/mercurial/bundlerepo.py	Tue Jan 12 14:48:27 2016 -0800
@@ -245,17 +245,14 @@
             fdtemp, temp = self.vfs.mkstemp(prefix="hg-bundle-",
                                             suffix=".hg10un")
             self.tempfile = temp
-            fptemp = os.fdopen(fdtemp, 'wb')
 
-            try:
+            with os.fdopen(fdtemp, 'wb') as fptemp:
                 fptemp.write(header)
                 while True:
                     chunk = read(2**18)
                     if not chunk:
                         break
                     fptemp.write(chunk)
-            finally:
-                fptemp.close()
 
             return self.vfs.open(self.tempfile, mode="rb")
         self._tempparent = None