[PATCH 2 of 2 V3] util: use a context manager in readlock()

Matt Harbison mharbison72 at gmail.com
Fri Sep 28 22:33:20 EDT 2018


# HG changeset patch
# User Matt Harbison <matt_harbison at yahoo.com>
# Date 1538187525 14400
#      Fri Sep 28 22:18:45 2018 -0400
# Node ID cddac40b1a06c37cede9757914d930de92250612
# Parent  1b472f36e081a9a98e45f84a0cf34f5b6008dd47
util: use a context manager in readlock()

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -1848,10 +1848,8 @@ def readlock(pathname):
             raise
     except AttributeError: # no symlink in os
         pass
-    fp = posixfile(pathname, 'rb')
-    r = fp.read()
-    fp.close()
-    return r
+    with posixfile(pathname, 'rb') as fp:
+        return fp.read()
 
 def fstat(fp):
     '''stat file object that may not have fileno method.'''


More information about the Mercurial-devel mailing list