]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-154675: reorganize some imports in importlib (#154657)
authorBrett Cannon <brett@python.org>
Mon, 27 Jul 2026 20:18:53 +0000 (13:18 -0700)
committerGitHub <noreply@github.com>
Mon, 27 Jul 2026 20:18:53 +0000 (20:18 +0000)
Lib/importlib/abc.py
Lib/importlib/machinery.py
Lib/importlib/util.py

index 9ca127ad9c7d0fd023c203879c76d49a8be502ff..ec68379e76f6f311bb36a212065b56d821058a33 100644 (file)
@@ -1,6 +1,7 @@
 """Abstract base classes related to import."""
 from . import _bootstrap_external
 from . import machinery
+
 try:
     import _frozen_importlib
 except ImportError as exc:
@@ -11,10 +12,12 @@ try:
     import _frozen_importlib_external
 except ImportError:
     _frozen_importlib_external = _bootstrap_external
-from ._abc import Loader
 import abc
 
 
+# Public API
+from ._abc import Loader
+
 __all__ = [
     'Loader', 'MetaPathFinder', 'PathEntryFinder',
     'ResourceLoader', 'InspectLoader', 'ExecutionLoader',
index 023f77d750fd2bc1a3ac73c04fbf5a310d73b51a..b22e538862299fff6850bda5aca62e85267ef544 100644 (file)
@@ -1,5 +1,9 @@
 """The machinery of importlib: finders, loaders, hooks, etc."""
 
+lazy import warnings
+
+
+# Public API
 from ._bootstrap import ModuleSpec
 from ._bootstrap import BuiltinImporter
 from ._bootstrap import FrozenImporter
@@ -33,8 +37,6 @@ __all__ = ['AppleFrameworkLoader', 'BYTECODE_SUFFIXES', 'BuiltinImporter',
 
 
 def __getattr__(name):
-    import warnings
-
     if name == 'DEBUG_BYTECODE_SUFFIXES':
         warnings.warn('importlib.machinery.DEBUG_BYTECODE_SUFFIXES is '
                       'deprecated; use importlib.machinery.BYTECODE_SUFFIXES '
index 2b564e9b52e0cb247c66286e0c6a5788bd75c2cb..dbce696dc8d169ae9711e317650f221ee3182bbc 100644 (file)
@@ -1,19 +1,23 @@
 """Utility code for constructing importers, etc."""
+
+from ._bootstrap import _resolve_name
+from ._bootstrap import _find_spec
+
+import _imp
+import sys
+import types
+
+
+# Public API
 from ._abc import Loader
 from ._bootstrap import module_from_spec
-from ._bootstrap import _resolve_name
 from ._bootstrap import spec_from_loader
-from ._bootstrap import _find_spec
 from ._bootstrap_external import MAGIC_NUMBER
 from ._bootstrap_external import cache_from_source
 from ._bootstrap_external import decode_source
 from ._bootstrap_external import source_from_cache
 from ._bootstrap_external import spec_from_file_location
 
-import _imp
-import sys
-import types
-
 
 def source_hash(source_bytes):
     "Return the hash of *source_bytes* as used in hash-based pyc files."