summaryrefslogtreecommitdiff
path: root/Lib/tokenize.py
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2015-05-26 00:46:44 +0200
committerVictor Stinner <victor.stinner@gmail.com>2015-05-26 00:46:44 +0200
commit24d262af0b16f76415baa6187c8892de1682c8a6 (patch)
treea13a4f056c5c47989c637f1131a26fe473757126 /Lib/tokenize.py
parente6efbdc94760ba0ca410d037b55ac32020de5cb2 (diff)
parent387729e183365a366c48fce7a9abfcaf4ec6ff4e (diff)
downloadcpython-git-24d262af0b16f76415baa6187c8892de1682c8a6.tar.gz
(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.py14
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index d65325e62e..f58c286901 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):