[New-bugs-announce] [issue36128] ResourceReader for FileLoader inconsistently handles path separators

Gregory Szorc report at bugs.python.org
Tue Feb 26 16:05:00 EST 2019


New submission from Gregory Szorc <gregory.szorc at gmail.com>:

The implementation of the ResourceReader API for the FileLoader class in importlib/_bootstrap_external.py is inconsistent with regards to handling of path separators.

Specifically, "is_resource()" returns False if "resource" has a path separator. But "open_resource()" will happily open resources containing a path separator.

I would think the two would agree about whether a path with separators is a resource or not. The documentation at https://docs.python.org/3.7/library/importlib.html#importlib.abc.ResourceReader implies that resources in subdirectories should not be allowed.

One can easily demonstrate this behavior oddity with Mercurial:

(Pdb) p sys.modules['mercurial'].__spec__.loader.get_resource_reader('mercurial').open_resource('help/config.txt')
<_io.FileIO name='/home/gps/src/hg/mercurial/help/config.txt' mode='rb' closefd=True>
(Pdb) p sys.modules['mercurial'].__spec__.loader.get_resource_reader('mercurial').is_resource('help/config.txt')
False

The behavior has been present since the functionality was added (https://github.com/python/cpython/pull/5168).

----------
components: Library (Lib)
messages: 336712
nosy: barry, indygreg
priority: normal
severity: normal
status: open
title: ResourceReader for FileLoader inconsistently handles path separators
type: behavior
versions: Python 3.7, Python 3.8

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36128>
_______________________________________


More information about the New-bugs-announce mailing list