[3.13] gh-123987: Fix NotADirectoryError in NamespaceReader when sentinel present (GH-124018) (#129319)

gh-123987: Fix NotADirectoryError in NamespaceReader when sentinel present (GH-124018)
(cherry picked from commit b543b32eff)

Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
Miss Islington (bot) 2025-01-26 18:04:09 +01:00 committed by GitHub
parent 53b7b0f782
commit 6e887411b6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 93 additions and 18 deletions

View file

@ -55,6 +55,26 @@ class OpenZipTests(FilesTests, util.ZipSetup, unittest.TestCase):
class OpenNamespaceTests(FilesTests, util.DiskSetup, unittest.TestCase):
MODULE = 'namespacedata01'
def test_non_paths_in_dunder_path(self):
"""
Non-path items in a namespace package's ``__path__`` are ignored.
As reported in python/importlib_resources#311, some tools
like Setuptools, when creating editable packages, will inject
non-paths into a namespace package's ``__path__``, a
sentinel like
``__editable__.sample_namespace-1.0.finder.__path_hook__``
to cause the ``PathEntryFinder`` to be called when searching
for packages. In that case, resources should still be loadable.
"""
import namespacedata01
namespacedata01.__path__.append(
'__editable__.sample_namespace-1.0.finder.__path_hook__'
)
resources.files(namespacedata01)
class OpenNamespaceZipTests(FilesTests, util.ZipSetup, unittest.TestCase):
ZIP_MODULE = 'namespacedata01'
@ -81,7 +101,7 @@ def test_module_resources(self):
"""
A module can have resources found adjacent to the module.
"""
import mod
import mod # type: ignore[import-not-found]
actual = resources.files(mod).joinpath('res.txt').read_text(encoding='utf-8')
assert actual == self.spec['res.txt']