@@ -2,12 +2,9 @@ import sys
22import types
33from _typeshed import AnyPath
44from abc import ABCMeta , abstractmethod
5- from typing import IO , Any , Iterator , Mapping , Optional , Sequence , Tuple , Union
6- from typing_extensions import Literal
7-
8- # Loader is exported from this module, but for circular import reasons
9- # exists in its own stub file (with ModuleSpec and ModuleType).
10- from _importlib_modulespec import Loader as Loader , ModuleSpec # Exported
5+ from importlib .machinery import ModuleSpec
6+ from typing import IO , Any , Iterator , Mapping , Optional , Protocol , Sequence , Tuple , Union
7+ from typing_extensions import Literal , runtime_checkable
118
129_Path = Union [bytes , str ]
1310
@@ -54,6 +51,17 @@ class PathEntryFinder(Finder):
5451 # Not defined on the actual class, but expected to exist.
5552 def find_spec (self , fullname : str , target : Optional [types .ModuleType ] = ...) -> Optional [ModuleSpec ]: ...
5653
54+ class Loader (metaclass = ABCMeta ):
55+ def load_module (self , fullname : str ) -> types .ModuleType : ...
56+ def module_repr (self , module : types .ModuleType ) -> str : ...
57+ def create_module (self , spec : ModuleSpec ) -> Optional [types .ModuleType ]: ...
58+ # Not defined on the actual class for backwards-compatibility reasons,
59+ # but expected in new code.
60+ def exec_module (self , module : types .ModuleType ) -> None : ...
61+
62+ class _LoaderProtocol (Protocol ):
63+ def load_module (self , fullname : str ) -> types .ModuleType : ...
64+
5765class FileLoader (ResourceLoader , ExecutionLoader , metaclass = ABCMeta ):
5866 name : str
5967 path : _Path
@@ -74,7 +82,6 @@ if sys.version_info >= (3, 7):
7482 def contents (self ) -> Iterator [str ]: ...
7583
7684if sys .version_info >= (3 , 9 ):
77- from typing import Protocol , runtime_checkable
7885 @runtime_checkable
7986 class Traversable (Protocol ):
8087 @abstractmethod
0 commit comments