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 | 6b6a4488adc12d390c5e0c8f13829dd9bf125309 (patch) | |
tree | 4eeeeb857c02023fd46d610612f600d533105afb /coverage/execfile.py | |
parent | 2e5688eedd1576e9b100386c0a9ae30828123f73 (diff) | |
download | python-coveragepy-git-6b6a4488adc12d390c5e0c8f13829dd9bf125309.tar.gz |
with statements: no more finally close
--HG--
branch : 4.0
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 5d4ae690..71ec9318 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 |