Skip to content

Resource should not be path-like #241

@layday

Description

@layday

Resource is currently defined as:

Resource = Union[str, os.PathLike]

os.PathLike is:

An abstract base class for objects representing a file system path, e.g. pathlib.PurePath.

Resources are not file system entities and os.PathLike is therefore inappropriate. In addition, os.fspath is not used to convert Resources to strings, so functions which manipulate paths are unsafe:

In [1]: !python -m pip show importlib-resources | rg Version
Version: 5.3.0

In [2]: import importlib_resources

In [3]: class Foo:
   ...:     def __fspath__(self):
   ...:         return "__init__.py"
   ...:

In [4]: importlib_resources.open_text("asyncio", Foo())
  [...]
FileNotFoundError: [Errno 2] No such file or directory: '/nix/store/qx995zl14gqgx0ly0hwx3cy0fcz27ich-python3-3.9.6/lib/python3.9/asyncio/<__main__.Foo object at 0x11172d550>'

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions