diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2015-05-25 22:46:44 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2015-05-25 22:46:44 (GMT) |
commit | 24d262af0b16f76415baa6187c8892de1682c8a6 (patch) | |
tree | a13a4f056c5c47989c637f1131a26fe473757126 /Lib/tokenize.py | |
parent | e6efbdc94760ba0ca410d037b55ac32020de5cb2 (diff) | |
parent | 387729e183365a366c48fce7a9abfcaf4ec6ff4e (diff) | |
download | cpython-24d262af0b16f76415baa6187c8892de1682c8a6.zip cpython-24d262af0b16f76415baa6187c8892de1682c8a6.tar.gz cpython-24d262af0b16f76415baa6187c8892de1682c8a6.tar.bz2 |
(Merge 3.5) Issue #23840: tokenize.open() now closes the temporary binary file
on error to fix a resource warning.
Diffstat (limited to 'Lib/tokenize.py')
-rw-r--r-- | Lib/tokenize.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/tokenize.py b/Lib/tokenize.py index d65325e..f58c286 100644 --- a/Lib/tokenize.py +++ b/Lib/tokenize.py @@ -435,11 +435,15 @@ def open(filename): detect_encoding(). """ buffer = _builtin_open(filename, 'rb') - encoding, lines = detect_encoding(buffer.readline) - buffer.seek(0) - text = TextIOWrapper(buffer, encoding, line_buffering=True) - text.mode = 'r' - return text + try: + encoding, lines = detect_encoding(buffer.readline) + buffer.seek(0) + text = TextIOWrapper(buffer, encoding, line_buffering=True) + text.mode = 'r' + return text + except: + buffer.close() + raise def tokenize(readline): |