mirror of
https://github.com/python/cpython
synced 2024-09-05 08:17:45 +00:00
GH-109653: Defer import of `importlib.metadata._adapters
` (#109829)
* adapters * Add comments for deferred imports with links to rationale. * Add blurb --------- Co-authored-by: Jason R. Coombs <jaraco@jaraco.com>
This commit is contained in:
parent
667294d5b2
commit
6547330f4e
|
@ -18,7 +18,7 @@
|
|||
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 @@ 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')
|
||||
|
|
|
@ -12,8 +12,6 @@
|
|||
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()
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Deferred select imports in importlib.metadata and importlib.resources for a
|
||||
14% speedup.
|
Loading…
Reference in a new issue