diff options
| author | Victor Stinner <victor.stinner@gmail.com> | 2015-05-25 22:49:14 (GMT) |
|---|---|---|
| committer | Victor Stinner <victor.stinner@gmail.com> | 2015-05-25 22:49:14 (GMT) |
| commit | 6a0ee2b7dbe20b058f85b598645f97d24f091e45 (patch) | |
| tree | 0b05a68df4c71210e984ffc16435cf9527fd115f /Lib/tokenize.py | |
| parent | aea8fa357b06123d1e76590803be3e2d4dca1a8d (diff) | |
| parent | 24d262af0b16f76415baa6187c8892de1682c8a6 (diff) | |
| download | cpython-6a0ee2b7dbe20b058f85b598645f97d24f091e45.zip cpython-6a0ee2b7dbe20b058f85b598645f97d24f091e45.tar.gz cpython-6a0ee2b7dbe20b058f85b598645f97d24f091e45.tar.bz2 | |
(Merge 3.6) 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): |
