From patchwork Sun Jun 17 09:11:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2,of,2] extensions: use context manger for open() From: Yuya Nishihara X-Patchwork-Id: 32213 Message-Id: To: mercurial-devel@mercurial-scm.org Date: Sun, 17 Jun 2018 18:11:34 +0900 # HG changeset patch # User Yuya Nishihara # Date 1529226109 -32400 # Sun Jun 17 18:01:49 2018 +0900 # Node ID c6f82a18a63de52c95f0e6ee362ffd0fd4154ccd # Parent 2c1d983872f6049c73be18d5d9da938b1d61f8fd extensions: use context manger for open() diff --git a/mercurial/extensions.py b/mercurial/extensions.py --- a/mercurial/extensions.py +++ b/mercurial/extensions.py @@ -605,12 +605,10 @@ def _moduledoc(file): def _disabledhelp(path): '''retrieve help synopsis of a disabled extension (without importing)''' try: - file = open(path, 'rb') + with open(path, 'rb') as src: + doc = _moduledoc(src) except IOError: return - else: - doc = _moduledoc(file) - file.close() if doc: # extracting localized synopsis return gettext(doc)