From 6673723baa487e447135815e8aaf1bb41aa963bd Mon Sep 17 00:00:00 2001 From: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Date: Thu, 21 Mar 2024 03:49:10 +0000 Subject: [PATCH] GH-109653: Defer import of ``importlib.metadata._adapters`` (python/cpython#109829) --------- Co-authored-by: Jason R. Coombs --- importlib_metadata/__init__.py | 5 ++++- newsfragments/+.feature.rst | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 newsfragments/+.feature.rst diff --git a/importlib_metadata/__init__.py b/importlib_metadata/__init__.py index 32ee3b4d..f4c75941 100644 --- a/importlib_metadata/__init__.py +++ b/importlib_metadata/__init__.py @@ -18,7 +18,7 @@ import posixpath import collections -from . import _adapters, _meta +from . import _meta from .compat import py39 from ._collections import FreezableDefaultDict, Pair from ._compat import ( @@ -461,6 +461,9 @@ def metadata(self) -> _meta.PackageMetadata: 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/newsfragments/+.feature.rst b/newsfragments/+.feature.rst new file mode 100644 index 00000000..26618684 --- /dev/null +++ b/newsfragments/+.feature.rst @@ -0,0 +1 @@ +Deferred select imports in for speedup (python/cpython#109829).