diff options
author | Mats Wichmann <mats@linux.com> | 2018-07-24 21:44:48 (GMT) |
---|---|---|
committer | Mats Wichmann <mats@linux.com> | 2018-07-24 21:44:48 (GMT) |
commit | bde85d7501235a67bee32c65f83a9e4da52e3968 (patch) | |
tree | e0f510ce55a263c0cdc603a758d8e126899a399d | |
parent | ee03bf12b40248e89ada1e501cf52b9b7cd9f867 (diff) | |
download | SCons-bde85d7501235a67bee32c65f83a9e4da52e3968.zip SCons-bde85d7501235a67bee32c65f83a9e4da52e3968.tar.gz SCons-bde85d7501235a67bee32c65f83a9e4da52e3968.tar.bz2 |
Fix py3 ResourceWarning in TestCmd
class TestCmd method read() uses a shortcut to return data from
a file, "return open(...).read()". Python 3 warns this is a
resource leak because the file has no chance to be closed with
the open being in the return statement. Split into two lines
and use a context manager (with statement).
Signed-off-by: Mats Wichmann <mats@linux.com>
-rw-r--r-- | src/CHANGES.txt | 1 | ||||
-rw-r--r-- | testing/framework/TestCmd.py | 6 |
2 files changed, 5 insertions, 2 deletions
diff --git a/src/CHANGES.txt b/src/CHANGES.txt index 79d25db..e3a646c 100644 --- a/src/CHANGES.txt +++ b/src/CHANGES.txt @@ -102,6 +102,7 @@ RELEASE 3.1.0.alpha.yyyymmdd - NEW DATE WILL BE INSERTED HERE - xml validity fixes from SConstruct.py change - update wiki links to new github location - update bug links to new github location + - convert TestCmd.read to use with statement on open (quiets 17 py3 warnings) From Hao Wu - typo in customized decider example in user guide diff --git a/testing/framework/TestCmd.py b/testing/framework/TestCmd.py index 9cd6b39..9499ff4 100644 --- a/testing/framework/TestCmd.py +++ b/testing/framework/TestCmd.py @@ -1247,9 +1247,11 @@ class TestCmd(object): if mode[0] != 'r': raise ValueError("mode must begin with 'r'") if IS_PY3 and 'b' not in mode: - return open(file, mode, newline=newline).read() + with open(file, mode, newline=newline) as f: + return f.read() else: - return open(file, mode).read() + with open(file, mode) as f: + return f.read() def rmdir(self, dir): """Removes the specified dir name. |