diff --git a/importlib_resources/_common.py b/importlib_resources/_common.py index c989135..8df6b39 100644 --- a/importlib_resources/_common.py +++ b/importlib_resources/_common.py @@ -12,8 +12,6 @@ from typing import Union, Optional, cast from .abc import ResourceReader, Traversable -from .future.adapters import wrap_spec - Package = Union[types.ModuleType, str] Anchor = Package @@ -111,6 +109,9 @@ def from_package(package: types.ModuleType): Return a Traversable object for the given package. """ + # deferred for performance (python/cpython#109829) + from .future.adapters import wrap_spec + spec = wrap_spec(package) reader = spec.loader.get_resource_reader(spec.name) return reader.files() diff --git a/newsfragments/+.feature.rst b/newsfragments/+.feature.rst new file mode 100644 index 0000000..976f76f --- /dev/null +++ b/newsfragments/+.feature.rst @@ -0,0 +1 @@ +Deferred select imports in for a speedup (python/cpython#109829).