Message239786
| Author |
vstinner |
| Recipients |
vstinner |
| Date |
2015-04-01.11:52:32 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1427889153.26.0.649877902408.issue23840@psf.upfronthosting.co.za> |
| In-reply-to |
|
| Content |
If TextIOWrapper constructor fails in tokenize.open(), the open binary file is not closed and a ResourceWarning is emited.
Try attached patch:
$ python3 -Wd ~/tokenize_open_bug.py
tokenize.open failed: unknown encoding for 'test.py': xxx
/home/haypo/tokenize_open_bug.py:13: ResourceWarning: unclosed file <_io.BufferedReader name='test.py'>
print("tokenize.open failed: %s" % err)
The fix is quite simple: add "try: ... except: buffer.close(); raise". If someone wants to fix this issue, an unit test must be added, test based on my script and ensures that the buffer is closed (ex: mock tokenize._builtin_open and checks that close() was called). |
|
History
|
|---|
| Date |
User |
Action |
Args |
| 2015-04-01 11:52:33 | vstinner | set | recipients:
+ vstinner |
| 2015-04-01 11:52:33 | vstinner | set | messageid: <1427889153.26.0.649877902408.issue23840@psf.upfronthosting.co.za> |
| 2015-04-01 11:52:33 | vstinner | link | issue23840 messages |
| 2015-04-01 11:52:32 | vstinner | create | |
|