Patchwork [2,of,2] extensions: use context manger for open()

login
register
mail settings
Submitter Yuya Nishihara
Date June 17, 2018, 9:11 a.m.
Message ID <c6f82a18a63de52c95f0.1529226694@mimosa>
Download mbox | patch
Permalink /patch/32213/
State Accepted
Headers show

Comments

Yuya Nishihara - June 17, 2018, 9:11 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1529226109 -32400
#      Sun Jun 17 18:01:49 2018 +0900
# Node ID c6f82a18a63de52c95f0e6ee362ffd0fd4154ccd
# Parent  2c1d983872f6049c73be18d5d9da938b1d61f8fd
extensions: use context manger for open()

Patch

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)