2 from _typeshed import StrPath
3 from os import PathLike
4 from typing import IO, Any, Protocol, TypeVar
7 acquire_lock as acquire_lock,
8 create_dynamic as create_dynamic,
9 get_frozen_object as get_frozen_object,
10 init_frozen as init_frozen,
11 is_builtin as is_builtin,
12 is_frozen as is_frozen,
13 is_frozen_package as is_frozen_package,
14 lock_held as lock_held,
15 release_lock as release_lock,
31 def new_module(name: str) -> types.ModuleType: ...
32 def get_magic() -> bytes: ...
33 def get_tag() -> str: ...
34 def cache_from_source(path: StrPath, debug_override: bool | None = ...) -> str: ...
35 def source_from_cache(path: StrPath) -> str: ...
36 def get_suffixes() -> list[tuple[str, str, int]]: ...
39 def __init__(self, path: StrPath) -> None: ...
40 def find_module(self, fullname: Any) -> None: ...
42 # Technically, a text file has to support a slightly different set of operations than a binary file,
43 # but we ignore that here.
44 class _FileLike(Protocol):
47 def read(self) -> str | bytes: ...
48 def close(self) -> Any: ...
49 def __enter__(self) -> Any: ...
50 def __exit__(self, *args: Any) -> Any: ...
52 # PathLike doesn't work for the pathname argument here
53 def load_source(name: str, pathname: str, file: _FileLike | None = ...) -> types.ModuleType: ...
54 def load_compiled(name: str, pathname: str, file: _FileLike | None = ...) -> types.ModuleType: ...
55 def load_package(name: str, path: StrPath) -> types.ModuleType: ...
56 def load_module(name: str, file: _FileLike | None, filename: str, details: tuple[str, str, int]) -> types.ModuleType: ...
58 # IO[Any] is a TextIOWrapper if name is a .py file, and a FileIO otherwise.
60 name: str, path: None | list[str] | list[PathLike[str]] | list[StrPath] = ...
61 ) -> tuple[IO[Any], str, tuple[str, str, int]]: ...
62 def reload(module: types.ModuleType) -> types.ModuleType: ...
63 def init_builtin(name: str) -> types.ModuleType | None: ...
64 def load_dynamic(name: str, path: str, file: Any = ...) -> types.ModuleType: ... # file argument is ignored