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 commented on Jul 1, 2024
TERM=dumb does not enable the old REPL. The env var is called PYTHON_BASIC_REPL.
danielhollas commented on 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_REPL will actually run the old REPL directly, and will produce the same behaviour as in 3.12
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).
whitphx commented on May 22, 2025
#134275 should fix the new REPL's different behavior than the old one,
while the issue below still is there
whitphx commented on Sep 5, 2025
Hi from PyConTW sprint.
SpecLoaderAdapter accesses spec's attributes such as spec.name
cpython/Lib/importlib/resources/_adapters.py
Line 17 in fc0305a
while spec can be None when the package is __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 where package.__spec__ is None.
Let me take a closer look...
>>> 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'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 commented on 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…