Author vstinner
Recipients vstinner
Date 2015-04-01.11:52:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
If TextIOWrapper constructor fails in, the open binary file is not closed and a ResourceWarning is emited.

Try attached patch:

$ python3 -Wd ~/ failed: unknown encoding for '': xxx
/home/haypo/ ResourceWarning: unclosed file <_io.BufferedReader name=''>
  print(" 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).
Date User Action Args
2015-04-01 11:52:33vstinnersetrecipients: + vstinner
2015-04-01 11:52:33vstinnersetmessageid: <>
2015-04-01 11:52:33vstinnerlinkissue23840 messages
2015-04-01 11:52:32vstinnercreate