diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2013-10-20 07:58:57 -0400 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2013-10-20 07:58:57 -0400 |
commit | 249ad14dfedbe45919b48dbbff445394a64d985c (patch) | |
tree | f88f6356df0087c28e8d18a434e5e9142359352f /coverage/execfile.py | |
parent | f0459a54bb3e703691359aa3078a8234173ec361 (diff) | |
download | python-coveragepy-249ad14dfedbe45919b48dbbff445394a64d985c.tar.gz |
with statements: no more finally close
Diffstat (limited to 'coverage/execfile.py')
-rw-r--r-- | coverage/execfile.py | 8 |
1 files changed, 2 insertions, 6 deletions
diff --git a/coverage/execfile.py b/coverage/execfile.py index 5d4ae69..71ec931 100644 --- a/coverage/execfile.py +++ b/coverage/execfile.py @@ -129,10 +129,8 @@ def make_code_from_py(filename): except IOError: raise NoSource("No file to run: %r" % filename) - try: + with source_file: source = source_file.read() - finally: - source_file.close() # We have the source. `compile` still needs the last line to be clean, # so make sure it is, then compile a code object from it. @@ -150,7 +148,7 @@ def make_code_from_pyc(filename): except IOError: raise NoCode("No file to run: %r" % filename) - try: + with fpyc: # First four bytes are a version-specific magic number. It has to # match or we won't run the file. magic = fpyc.read(4) @@ -165,7 +163,5 @@ def make_code_from_pyc(filename): # The rest of the file is the code object we want. code = marshal.load(fpyc) - finally: - fpyc.close() return code |