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/parser.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/parser.py')
-rw-r--r-- | coverage/parser.py | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/coverage/parser.py b/coverage/parser.py index 37beeded..d0fe9976 100644 --- a/coverage/parser.py +++ b/coverage/parser.py @@ -25,11 +25,8 @@ class CodeParser(object): self.text = text if not self.text: try: - sourcef = open_source(self.filename) - try: + with open_source(self.filename) as sourcef: self.text = sourcef.read() - finally: - sourcef.close() except IOError: _, err, _ = sys.exc_info() raise NoSource( @@ -328,11 +325,8 @@ class ByteParser(object): else: if not text: assert filename, "If no code or text, need a filename" - sourcef = open_source(filename) - try: + with open_source(filename) as sourcef: text = sourcef.read() - finally: - sourcef.close() self.text = text try: |