summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/importlib/metadata/__init__.py5
-rw-r--r--Lib/importlib/resources/_common.py5
-rw-r--r--Misc/NEWS.d/next/Library/2024-03-20-23-07-58.gh-issue-109653.uu3lrX.rst2
3 files changed, 9 insertions, 3 deletions
diff --git a/Lib/importlib/metadata/__init__.py b/Lib/importlib/metadata/__init__.py
index c8e59ca..245f905 100644
--- a/Lib/importlib/metadata/__init__.py
+++ b/Lib/importlib/metadata/__init__.py
@@ -18,7 +18,7 @@ import itertools
import posixpath
import collections
-from . import _adapters, _meta
+from . import _meta
from ._collections import FreezableDefaultDict, Pair
from ._functools import method_cache, pass_none
from ._itertools import always_iterable, unique_everseen
@@ -456,6 +456,9 @@ class Distribution(DeprecatedNonAbstract):
Custom providers may provide the METADATA file or override this
property.
"""
+ # deferred for performance (python/cpython#109829)
+ from . import _adapters
+
opt_text = (
self.read_text('METADATA')
or self.read_text('PKG-INFO')
diff --git a/Lib/importlib/resources/_common.py b/Lib/importlib/resources/_common.py
index a390253..e18082f 100644
--- a/Lib/importlib/resources/_common.py
+++ b/Lib/importlib/resources/_common.py
@@ -12,8 +12,6 @@ import itertools
from typing import Union, Optional, cast
from .abc import ResourceReader, Traversable
-from ._adapters import wrap_spec
-
Package = Union[types.ModuleType, str]
Anchor = Package
@@ -109,6 +107,9 @@ def from_package(package: types.ModuleType):
Return a Traversable object for the given package.
"""
+ # deferred for performance (python/cpython#109829)
+ from ._adapters import wrap_spec
+
spec = wrap_spec(package)
reader = spec.loader.get_resource_reader(spec.name)
return reader.files()
diff --git a/Misc/NEWS.d/next/Library/2024-03-20-23-07-58.gh-issue-109653.uu3lrX.rst b/Misc/NEWS.d/next/Library/2024-03-20-23-07-58.gh-issue-109653.uu3lrX.rst
new file mode 100644
index 0000000..38d7634
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-03-20-23-07-58.gh-issue-109653.uu3lrX.rst
@@ -0,0 +1,2 @@
+Deferred select imports in importlib.metadata and importlib.resources for a
+14% speedup.