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.

Files
File name Uploaded Description Edit
fix_resource_warning_read_mime_types.patch vajrasky,2013-08-06 15:31 review
fix_resource_warning_read_mime_types_v2.patch vajrasky,2013-08-11 16:00 review
fix_resource_warning_read_mime_types_v3.patch vajrasky,2014-01-24 09:32 review
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) * (Python committer) 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) * (Python committer) 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) * (Python committer) Date: 2020-06-20 08:55
It was fixed in .
History
Date User Action Args
2022-04-11 14:57:49 admin set github: 62870
2020-06-20 08:55:45 serhiy.storchaka set status: open -> closednosy: + serhiy.storchakamessages: + resolution: out of datestage: patch review -> resolved
2017-10-27 22:09:33 martin.panter set nosy: + martin.pantermessages: +
2014-01-24 09:32:43 vajrasky set files: + fix_resource_warning_read_mime_types_v3.patchmessages: +
2013-08-11 16:20:07 ezio.melotti set nosy: + ezio.melottistage: patch reviewversions: + Python 3.3
2013-08-11 16:00:13 vajrasky set files: + fix_resource_warning_read_mime_types_v2.patchmessages: +
2013-08-09 16:28:52 r.david.murray set nosy: + r.david.murraymessages: +
2013-08-06 15:31:44 vajrasky create