Message387808
I've pushed [this branch](https://github.com/python/cpython/tree/feature/42129-resources-namespace-packages), which includes fixes for the above two identified issues. Still one issue remains:
ERROR: test_package_has_no_reader_fallback (test.test_importlib.test_resource.ResourceCornerCaseTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/Users/jaraco/code/public/cpython/Lib/test/test_importlib/test_resource.py", line 98, in test_package_has_no_reader_fallback
self.assertFalse(resources.is_resource(module, 'A'))
File "/Users/jaraco/code/public/cpython/Lib/importlib/resources.py", line 157, in is_resource
package_contents = set(contents(package))
File "/Users/jaraco/code/public/cpython/Lib/importlib/resources.py", line 174, in contents
transversable = _common.from_package(package)
File "/Users/jaraco/code/public/cpython/Lib/importlib/_common.py", line 75, in from_package
reader = spec.loader.get_resource_reader(spec.name)
AttributeError: 'object' object has no attribute 'get_resource_reader'
This same test passes on importlib_resources, and the difference seems to be rooted in how [from_package resolves the package spec using a compatibility wrapper](https://github.com/python/importlib_resources/blob/1401cc48e5077088036aa7e729c8995ffbbb9e88/importlib_resources/_common.py#L76). On the backport, this causes the package without a resource reader to have a resource reader and return a degenerate value:
```
> /Users/jaraco/code/public/importlib_resources/importlib_resources/_py3.py(139)is_resource()
-> package_contents = set(contents(package))
(Pdb) _common.from_package(package)
PosixPath('/path/which/shall/not/be')
(Pdb) from . import _compat
(Pdb) _compat.package_spec(package).loader.get_resource_reader('any').files().is_dir()
False
```
This means that the compatibility shim in from_package is masking test failure in the backport, and probably the best course of action will be to unmask that failure in the backport and figure out the best behavior there. |
|
Date |
User |
Action |
Args |
2021-02-28 10:11:20 | jaraco | set | recipients:
+ jaraco, barry, brett.cannon, FFY00 |
2021-02-28 10:11:19 | jaraco | set | messageid: <1614507079.98.0.343082997046.issue42129@roundup.psfhosted.org> |
2021-02-28 10:11:19 | jaraco | link | issue42129 messages |
2021-02-28 10:11:19 | jaraco | create | |
|