mirror of
https://gerrit.googlesource.com/git-repo
synced 2025-06-26 20:17:52 +00:00
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>
This commit is contained in:
@ -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)
|
||||
|
Reference in New Issue
Block a user