Issue 18670: Using read_mime_types function from mimetypes module gives resource warning (original ) (raw )Created on 2013-08-06 15:31 by vajrasky , last changed 2022-04-11 14:57 by admin . This issue is now closed .
Messages (6)
msg194557 - (view)
Author: Vajrasky Kok (vajrasky) *
Date: 2013-08-06 15:31
[sky@localhost cpython]$ cat /tmp/a.txt x-application/mimea mimea application/mimeb mimeb [sky@localhost cpython]$ cat /tmp/a.py import warnings warnings.simplefilter('default') import mimetypes mimetypes.read_mime_types('/tmp/a.txt') [sky@localhost cpython]$ python3 /tmp/a.py /tmp/a.py:7: ResourceWarning: unclosed file <_io.TextIOWrapper name='/tmp/a.txt' mode='r' encoding='UTF-8'> mimetypes.read_mime_types('/tmp/a.txt') Attached the patch to fix the resource warning problem.
msg194751 - (view)
Author: R. David Murray (r.david.murray) *
Date: 2013-08-09 16:28
Since the TESTFN file is created only in this test, rather than use a tearDown method, it would be better to use addCleanup in the test method itself.
msg194898 - (view)
Author: Vajrasky Kok (vajrasky) *
Date: 2013-08-11 16:00
Attached the second patch to use addCleanup rather than tear down method. Also, I added the non-existent file case.
msg209054 - (view)
Author: Vajrasky Kok (vajrasky) *
Date: 2014-01-24 09:32
Here is the updated patch based on Ezio's review. Sorry, for a long time, I didn't notice you had reviewed my code, Ezio. Thanks for the review!
msg305139 - (view)
Author: Martin Panter (martin.panter) *
Date: 2017-10-27 22:09
The patches would mask an OSError raised by the “readfp” call, which would be a change in behaviour. But moving the call does not seem to be necessary; why not leave it outside the “try” statement?
msg371924 - (view)
Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2020-06-20 08:55
It was fixed in .