You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Different output from importlib.resources.files() in REPL in 3.12 versus 3.13 #121190
It would be nice to return something more helpful. The documentation doesn't mention that this function can raise, so I am assuming that raising AttributeError is not part of the public API?
However, on a locally built Python from current main branch, this call returns a path to Lib/_pyrepl. Even more surprising though is that this also happens when running the OLD REPL with TERM=dumb ./python
Note that I am not saying that the pyrepl behaviour is wrong here, just noting the difference. If anything, I'd change the behaviour in the old REPL so that at least it fails a bit more gracefully (not an obscure AttributeError).
#134275 should fix the new REPL's different behavior than the old one,
while the issue below still is there
It would be nice to return something more helpful. The documentation doesn't mention that this function can raise, so I am assuming that raising AttributeError is not part of the public API?
>>> import importlib_resources
>>> importlib_resources.files()
Traceback (most recent call last):
File "<python-input-1>", line 1, in <module>
importlib_resources.files()
~~~~~~~~~~~~~~~~~~~~~~~~~^^
File "/workspace/cpython/.venv/lib/python3.15/site-packages/importlib_resources/_common.py", line 45, in wrapper
return func()
File "/workspace/cpython/.venv/lib/python3.15/site-packages/importlib_resources/_common.py", line 56, in files
return from_package(resolve(anchor))
File "/workspace/cpython/.venv/lib/python3.15/site-packages/importlib_resources/_common.py", line 117, in from_package
reader = spec.loader.get_resource_reader(spec.name)
^^^^^^^^^
File "/workspace/cpython/.venv/lib/python3.15/site-packages/importlib_resources/_adapters.py", line 17, in __getattr__
return getattr(self.spec, name)
AttributeError: 'NoneType' object has no attribute 'name'
Activity
lysnikolaou commentedon Jul 1, 2024
TERM=dumbdoes not enable the old REPL. The env var is calledPYTHON_BASIC_REPL.danielhollas commentedon Jul 1, 2024
Well, while it may not enable it explicitly, implicitly it does since pyrepl will not start with this type of terminal.
But you are right that actually using
PYTHON_BASIC_REPLwill actually run the old REPL directly, and will produce the same behaviour as in 3.12Note that I am not saying that the pyrepl behaviour is wrong here, just noting the difference. If anything, I'd change the behaviour in the old REPL so that at least it fails a bit more gracefully (not an obscure AttributeError).
whitphx commentedon May 22, 2025
#134275 should fix the new REPL's different behavior than the old one,
while the issue below still is there
whitphx commentedon Sep 5, 2025
Hi from PyConTW sprint.
SpecLoaderAdapteraccessesspec's attributes such asspec.namecpython/Lib/importlib/resources/_adapters.py
Line 17 in fc0305a
while
speccan beNonewhen thepackageis__main__as documented.cpython/Lib/importlib/resources/_adapters.py
Line 168 in fc0305a
importlib.resources._common.from_package(package)needs to take care of the case wherepackage.__spec__isNone.Let me take a closer look...
importlib.resourcessynched with https://github.com/python/importlib_resources, andimportlib_resourcesalso has the same problem as this issue.Merge branch 'main' into pythongh-121190
pythongh-121190: Emit a better error message in `importlib.resources.…
gh-121190: Emit a better error message from `importlib.resources.file…
jaraco commentedon Apr 12, 2026
This change should be included in Python 3.15. Thanks for the patience awaiting merge.
Revert "pythongh-121190: Emit a better error message from `importlib.…
pythongh-121190: Emit a better error message from `importlib.resource…