This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: importlib.resources.read_text() raises FileNotFound
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Zac Hatfield-Dodds, barry, brett.cannon, jaraco
Priority: normal Keywords:

Created on 2021-12-09 11:22 by Zac Hatfield-Dodds, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg408107 - (view) Author: Zac Hatfield-Dodds (Zac Hatfield-Dodds) * Date: 2021-12-09 11:22
Testing Hypothesis with Python 3.11.0a3, I've triggered a frustrating regression in importlib.resources:


# Both work in Python 3.9 and 3.10, but both fail in 3.11.0a3
from importlib.resources import files, read_text
read_text("hypothesis.vendor", "tlds-alpha-by-domain.txt")
files("hypothesis.vendor").joinpath("tlds-alpha-by-domain.txt").read_text()


Traceback (most recent call last):
  ...
  File "example.py", line 4, in <module>
    read_text("hypothesis.vendor", "tlds-alpha-by-domain.txt")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/importlib/_legacy.py", line 25, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/importlib/_legacy.py", line 67, in read_text
    with open_text(package, resource, encoding, errors) as fp:
         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/importlib/_legacy.py", line 25, in wrapper
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/importlib/_legacy.py", line 50, in open_text
    return (_common.files(package) / _common.normalize_path(resource)).open(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "python3.11/importlib/_adapters.py", line 141, in open
    raise FileNotFoundError("Can't open orphan path")
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
FileNotFoundError: Can't open orphan path


At first I thought this was just a problem with the _legacy shims, but since it also affects the new files() API it might be more serious.
msg408108 - (view) Author: Zac Hatfield-Dodds (Zac Hatfield-Dodds) * Date: 2021-12-09 11:23
This may have appeared in the wild, via the backport, in

https://github.com/Nuitka/Nuitka/issues/1274 and
https://github.com/Nuitka/Nuitka/commit/ffe861cfe972c6bf19f9eea1ff95e35d0e4240b4
History
Date User Action Args
2022-04-11 14:59:53adminsetgithub: 90184
2021-12-09 11:23:59Zac Hatfield-Doddssetmessages: + msg408108
2021-12-09 11:22:57Zac Hatfield-Doddssetnosy: + brett.cannon, jaraco
2021-12-09 11:22:12Zac Hatfield-Doddscreate