mirror of
https://chromium.googlesource.com/chromium/tools/depot_tools.git
synced 2026-01-11 18:51:29 +00:00
[cpplint] Use with statement to ensure file descriptor is closed
When running on macOS under python3 as part of PRESUBMIT_test.py, a ResourceWarning is printed. This is due to the `open(..).read()` idiom. Use a `with` statement to ensure the file is properly closed. Bug: none Change-Id: I5643db0b77e6896b4b86177d2c1fe8dea04b58ae Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/4742422 Reviewed-by: Gavin Mak <gavinmak@google.com> Auto-Submit: Sylvain Defresne <sdefresne@chromium.org> Commit-Queue: Gavin Mak <gavinmak@google.com>
This commit is contained in:
committed by
LUCI CQ
parent
43083529de
commit
071df9a729
3
cpplint.py
vendored
3
cpplint.py
vendored
@@ -6244,7 +6244,8 @@ def ProcessFile(filename, vlevel, extra_check_functions=[]):
|
||||
codecs.getwriter('utf8'),
|
||||
'replace').read().split('\n')
|
||||
else:
|
||||
lines = codecs.open(filename, 'r', 'utf8', 'replace').read().split('\n')
|
||||
with codecs.open(filename, 'r', 'utf8', 'replace') as stream:
|
||||
lines = stream.read().split('\n')
|
||||
|
||||
# Remove trailing '\r'.
|
||||
# The -1 accounts for the extra trailing blank line we get from split()
|
||||
|
||||
Reference in New Issue
Block a user