summaryrefslogtreecommitdiffstats
path: root/editor.py
diff options
context:
space:
mode:
authorMike Frysinger <vapier@google.com>2019-11-11 05:40:22 -0500
committerMike Frysinger <vapier@google.com>2019-11-12 03:44:39 +0000
commit3164d40e2247d42537aef8e80fa7e048e14bec9f (patch)
tree650cc33e3d5c4b39c3cc652e93495e47a170931b /editor.py
parentf4545126197781beb03bb0fd47e7f24ce5af6ca8 (diff)
downloadgit-repo-3164d40e2247d42537aef8e80fa7e048e14bec9f.tar.gz
use open context managers in more places
Use open() as a context manager to simplify the close logic and make the code easier to read & understand. This is also more Pythonic. Change-Id: I579d03cca86f99b2c6c6a1f557f6e5704e2515a7 Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/244734 Reviewed-by: David Pursehouse <dpursehouse@collab.net> Tested-by: Mike Frysinger <vapier@google.com>
Diffstat (limited to 'editor.py')
-rw-r--r--editor.py5
1 files changed, 1 insertions, 4 deletions
diff --git a/editor.py b/editor.py
index b761eb57..19b96c37 100644
--- a/editor.py
+++ b/editor.py
@@ -106,11 +106,8 @@ least one of these before using this command.""", file=sys.stderr)
106 raise EditorError('editor failed with exit status %d: %s %s' 106 raise EditorError('editor failed with exit status %d: %s %s'
107 % (rc, editor, path)) 107 % (rc, editor, path))
108 108
109 fd2 = open(path) 109 with open(path) as fd2:
110 try:
111 return fd2.read() 110 return fd2.read()
112 finally:
113 fd2.close()
114 finally: 111 finally:
115 if fd: 112 if fd:
116 os.close(fd) 113 os.close(fd)