Skip to content
Prev Previous commit
Next Next commit
Modify the error message
  • Loading branch information
whitphx committed Sep 7, 2025
commit e25491eb5e6286d0cf0ba143c4b08ecb317e0720
5 changes: 4 additions & 1 deletion Lib/importlib/resources/_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ def from_package(package: types.ModuleType):
from ._adapters import wrap_spec

if package.__spec__ is None:
raise TypeError(f"Can't access resources on a module with no spec: {package}")
raise TypeError(
f"Cannot access resources because the code used to populate '{package.__name__}' "
"does not correspond directly with an importable module."
Comment thread
whitphx marked this conversation as resolved.
Outdated
)

spec = wrap_spec(package.__spec__)
reader = spec.loader.get_resource_reader(spec.name)
Expand Down
Loading