From 3164d40e2247d42537aef8e80fa7e048e14bec9f Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Mon, 11 Nov 2019 05:40:22 -0500 Subject: 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 Tested-by: Mike Frysinger --- editor.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'editor.py') 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) raise EditorError('editor failed with exit status %d: %s %s' % (rc, editor, path)) - fd2 = open(path) - try: + with open(path) as fd2: return fd2.read() - finally: - fd2.close() finally: if fd: os.close(fd) -- cgit v1.2.3-54-g00ecf