Skip to content

files(...).joinpath doesn't accept variable number of arguments in Python 3.10+ #257

@Jakub-CZ

Description

@Jakub-CZ

This happens to me when I try to access resources in a native namespace package.

Tested on:

  • Windows, Python 3.10.4
  • Docker in WSL2, image python:3.10-slim, Python 3.10.5

The reason seems to be that importlib_resources.files() returns MultiplexedPath from stdlib (importlib.readers) rather than from importlib_resources.readers.

To recreate:

  1. Install any namespace package, e.g. sphinxcontrib-htmlhelp;

    pip install sphinxcontrib-htmlhelp
    
  2. Use files with joinpath to get the path of a resource.

    from importlib_resources import files
    
    print(root:=files('sphinxcontrib'), 'from', root.__module__)
    print(root.joinpath('htmlhelp', 'templates'))

Expected output (which I get with Pythons 3.7-3.9):

MultiplexedPath('/usr/local/lib/python3.9/site-packages/sphinxcontrib') from importlib_resources.readers
/usr/local/lib/python3.9/site-packages/sphinxcontrib/htmlhelp/templates

Bug with Pythons 3.10:

MultiplexedPath('/usr/local/lib/python3.10/site-packages/sphinxcontrib') from importlib.readers
Traceback (most recent call last):
  File "<string>", line 1, in <module>
TypeError: MultiplexedPath.joinpath() takes 2 positional arguments but 3 were given

I also tested with the code in #254 but to no aval.

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