[PATCH 2 of 2] extensions: use context manger for open()
Yuya Nishihara
yuya at tcha.org
Sun Jun 17 05:11:34 EDT 2018
# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# 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)
More information about the Mercurial-devel
mailing list