Skip to content

Commit 12fbb96

Browse files
committed
Use lazy imports in the top-level modules of importlib
1 parent 9560bd8 commit 12fbb96

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

Lib/importlib/machinery.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
"""The machinery of importlib: finders, loaders, hooks, etc."""
22

3+
lazy import warnings
4+
5+
6+
# Public API
37
from ._bootstrap import ModuleSpec
48
from ._bootstrap import BuiltinImporter
59
from ._bootstrap import FrozenImporter
@@ -33,8 +37,6 @@ def all_suffixes():
3337

3438

3539
def __getattr__(name):
36-
import warnings
37-
3840
if name == 'DEBUG_BYTECODE_SUFFIXES':
3941
warnings.warn('importlib.machinery.DEBUG_BYTECODE_SUFFIXES is '
4042
'deprecated; use importlib.machinery.BYTECODE_SUFFIXES '

Lib/importlib/util.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
"""Utility code for constructing importers, etc."""
2+
3+
from ._bootstrap import _resolve_name
4+
from ._bootstrap import _find_spec
5+
6+
import sys
7+
import types
8+
9+
lazy import _imp
10+
11+
12+
# Public API
213
from ._abc import Loader
314
from ._bootstrap import module_from_spec
4-
from ._bootstrap import _resolve_name
515
from ._bootstrap import spec_from_loader
6-
from ._bootstrap import _find_spec
716
from ._bootstrap_external import MAGIC_NUMBER
817
from ._bootstrap_external import cache_from_source
918
from ._bootstrap_external import decode_source
1019
from ._bootstrap_external import source_from_cache
1120
from ._bootstrap_external import spec_from_file_location
1221

13-
import _imp
14-
import sys
15-
import types
16-
1722

1823
def source_hash(source_bytes):
1924
"Return the hash of *source_bytes* as used in hash-based pyc files."

0 commit comments

Comments
 (0)