Jason R. Coombs <jar...@jaraco.com> added the comment:

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.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42129>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to