[Python-checkins] bpo-44771: Sync with importlib_resources 5.2.2, fixing refleak. (#27497)

jaraco webhook-mailer at python.org
Fri Jul 30 20:37:40 EDT 2021


https://github.com/python/cpython/commit/e63e6311aa258a5f3f49a7aed9fdde445fd384d6
commit: e63e6311aa258a5f3f49a7aed9fdde445fd384d6
branch: main
author: Jason R. Coombs <jaraco at jaraco.com>
committer: jaraco <jaraco at jaraco.com>
date: 2021-07-30T20:37:09-04:00
summary:

bpo-44771: Sync with importlib_resources 5.2.2, fixing refleak. (#27497)

* bpo-44771: Sync with importlib_resources 5.2.2, fixing refleak.

* Include new 'resources' dir in the Makefile.

files:
M Lib/importlib/_common.py
M Makefile.pre.in

diff --git a/Lib/importlib/_common.py b/Lib/importlib/_common.py
index 74654b34ed5a9..9b126f3174974 100644
--- a/Lib/importlib/_common.py
+++ b/Lib/importlib/_common.py
@@ -87,14 +87,16 @@ def _tempfile(reader, suffix=''):
     # properly.
     fd, raw_path = tempfile.mkstemp(suffix=suffix)
     try:
-        os.write(fd, reader())
-        os.close(fd)
+        try:
+            os.write(fd, reader())
+        finally:
+            os.close(fd)
         del reader
         yield pathlib.Path(raw_path)
     finally:
         try:
             os.remove(raw_path)
-        except (FileNotFoundError, PermissionError):
+        except FileNotFoundError:
             pass
 
 
diff --git a/Makefile.pre.in b/Makefile.pre.in
index bf023a084dc47..f503ac4d87672 100644
--- a/Makefile.pre.in
+++ b/Makefile.pre.in
@@ -1516,6 +1516,7 @@ TESTSUBDIRS=	ctypes/test \
 		test/test_importlib/namespace_pkgs/project3/parent/child \
 		test/test_importlib/namespacedata01 \
 		test/test_importlib/partial \
+		test/test_importlib/resources \
 		test/test_importlib/source \
 		test/test_importlib/zipdata01 \
 		test/test_importlib/zipdata02 \



More information about the Python-checkins mailing list