New submission from Xiao Di Guan <x...@puxlit.net>:
Following changes introduced in bpo-15002, HTTPError closes its fp when GCed via tempfile._TemporaryFileCloser's finalizer. However, the current implementation of _TemporaryFileCloser only defines __del__ for non-NT platforms. Assuming HTTPError.fp is part of the API (though it's currently undocumented), and assuming the desired behaviour is to close fp when HTTPError is finalized, then perhaps _TemporaryFileCloser should always define __del__? A contrived example follows: ``` from urllib.error import HTTPError from urllib.request import urlopen def make_request(): try: urlopen('https://httpbin.org/status/418') assert False except HTTPError as err: assert err.code == 418 return err.fp fp = make_request() assert fp.isclosed() # Fails on Windows, passes on other platforms ``` ---------- components: Library (Lib) messages: 327532 nosy: puxlit priority: normal severity: normal status: open title: urllib.error.HTTPError.fp is not closed when error is finalized on Windows type: behavior versions: Python 3.4, Python 3.5, Python 3.6, Python 3.7 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue34958> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com