[Python-checkins] Don't crash if there exists an EGG-INFO directory on sys.path (#13667)

Barry Warsaw webhook-mailer at python.org
Wed May 29 20:13:18 EDT 2019


https://github.com/python/cpython/commit/80878312316bfb4011157f13cf040f6d885f808b
commit: 80878312316bfb4011157f13cf040f6d885f808b
branch: master
author: Anthony Sottile <asottile at umich.edu>
committer: Barry Warsaw <barry at python.org>
date: 2019-05-29T17:13:11-07:00
summary:

Don't crash if there exists an EGG-INFO directory on sys.path (#13667)

* Don't crash if there exists an EGG-INFO directory on sys.path

cross-port of https://gitlab.com/python-devs/importlib_metadata/merge_requests/72

* Also catch PermissionError for windows

files:
M Lib/importlib/metadata/__init__.py
M Lib/test/test_importlib/test_main.py

diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py
index 24d45d2caad0..a1abdd64815b 100644
--- a/Lib/importlib/metadata/__init__.py
+++ b/Lib/importlib/metadata/__init__.py
@@ -320,7 +320,8 @@ def __init__(self, path):
         self._path = path
 
     def read_text(self, filename):
-        with suppress(FileNotFoundError, NotADirectoryError, KeyError):
+        with suppress(FileNotFoundError, IsADirectoryError, KeyError,
+                      NotADirectoryError, PermissionError):
             return self._path.joinpath(filename).read_text(encoding='utf-8')
     read_text.__doc__ = Distribution.read_text.__doc__
 
diff --git a/Lib/test/test_importlib/test_main.py b/Lib/test/test_importlib/test_main.py
index b70f9440f697..844ed26c3ec7 100644
--- a/Lib/test/test_importlib/test_main.py
+++ b/Lib/test/test_importlib/test_main.py
@@ -156,3 +156,11 @@ def test_package_discovery(self):
             dist.metadata['Name'] == 'distinfo-pkg'
             for dist in dists
             )
+
+
+class DirectoryTest(fixtures.OnSysPath, fixtures.SiteDir, unittest.TestCase):
+    def test(self):
+        # make an `EGG-INFO` directory that's unrelated
+        self.site_dir.joinpath('EGG-INFO').mkdir()
+        # used to crash with `IsADirectoryError`
+        self.assertIsNone(version('unknown-package'))



More information about the Python-checkins mailing list