Format: application/octet-stream
⬇ Download File (2.3 KB)
   1  import os
   2  import types
   3  from _typeshed import StrPath
   4  from typing import IO, Any, List, Optional, Protocol, Tuple, TypeVar, Union
   5  
   6  from _imp import (
   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,
  16  )
  17  
  18  _T = TypeVar("_T")
  19  
  20  SEARCH_ERROR: int
  21  PY_SOURCE: int
  22  PY_COMPILED: int
  23  C_EXTENSION: int
  24  PY_RESOURCE: int
  25  PKG_DIRECTORY: int
  26  C_BUILTIN: int
  27  PY_FROZEN: int
  28  PY_CODERESOURCE: int
  29  IMP_HOOK: int
  30  
  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: Optional[bool] = ...) -> str: ...
  35  def source_from_cache(path: StrPath) -> str: ...
  36  def get_suffixes() -> List[Tuple[str, str, int]]: ...
  37  
  38  class NullImporter:
  39      def __init__(self, path: StrPath) -> None: ...
  40      def find_module(self, fullname: Any) -> None: ...
  41  
  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):
  45      closed: bool
  46      mode: str
  47      def read(self) -> Union[str, bytes]: ...
  48      def close(self) -> Any: ...
  49      def __enter__(self) -> Any: ...
  50      def __exit__(self, *args: Any) -> Any: ...
  51  
  52  # PathLike doesn't work for the pathname argument here
  53  def load_source(name: str, pathname: str, file: Optional[_FileLike] = ...) -> types.ModuleType: ...
  54  def load_compiled(name: str, pathname: str, file: Optional[_FileLike] = ...) -> types.ModuleType: ...
  55  def load_package(name: str, path: StrPath) -> types.ModuleType: ...
  56  def load_module(name: str, file: Optional[_FileLike], filename: str, details: Tuple[str, str, int]) -> types.ModuleType: ...
  57  
  58  # IO[Any] is a TextIOWrapper if name is a .py file, and a FileIO otherwise.
  59  def find_module(
  60      name: str, path: Union[None, List[str], List[os.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) -> Optional[types.ModuleType]: ...
  64  def load_dynamic(name: str, path: str, file: Any = ...) -> types.ModuleType: ...  # file argument is ignored
  65