diff options
author | Ned Batchelder <ned@nedbatchelder.com> | 2011-01-30 11:49:52 -0500 |
---|---|---|
committer | Ned Batchelder <ned@nedbatchelder.com> | 2011-01-30 11:49:52 -0500 |
commit | 16943d29886df91300121fced970134d0c2b9806 (patch) | |
tree | 0e621681a8c90b7c7e3dabcaa0b241693129846b /coverage/parser.py | |
parent | fefc80883476d3974b3aee692ab274d1f563f7bb (diff) | |
download | python-coveragepy-git-16943d29886df91300121fced970134d0c2b9806.tar.gz |
A bunch more places where a file close should be in a finally clause.
Diffstat (limited to 'coverage/parser.py')
-rw-r--r-- | coverage/parser.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index a71ac102..3dee80eb 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -24,8 +24,10 @@ class CodeParser(object): if not self.text: try: sourcef = open_source(self.filename) - self.text = sourcef.read() - sourcef.close() + try: + self.text = sourcef.read() + finally: + sourcef.close() except IOError: _, err, _ = sys.exc_info() raise NoSource( @@ -303,8 +305,10 @@ class ByteParser(object): if not text: assert filename, "If no code or text, need a filename" sourcef = open(filename, 'rU') - text = sourcef.read() - sourcef.close() + try: + text = sourcef.read() + finally: + sourcef.close() try: # Python 2.3 and 2.4 don't like partial last lines, so be sure |