# HG changeset patch # User Matt Harbison # Date 2018-09-29 02:18:45 # Node ID 4017968f0a1d7dc581c8a7682c234a1b77f10e92 # Parent 5fe0b880200e006006322c52ccd623ef1daa1469 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.'''