From 252d79981b2d7b3318588e834580bb6298282cf7 Mon Sep 17 00:00:00 2001 From: Andrew Svetlov Date: Sun, 6 May 2018 18:40:56 +0300 Subject: [PATCH] Add a stub for sys.implementation (#2097) --- stdlib/3/sys.pyi | 186 +++++++++++++++++++++++++++-------------------- 1 file changed, 107 insertions(+), 79 deletions(-) diff --git a/stdlib/3/sys.pyi b/stdlib/3/sys.pyi index 0af8ea5ff..9874934b1 100644 --- a/stdlib/3/sys.pyi +++ b/stdlib/3/sys.pyi @@ -5,112 +5,125 @@ from typing import ( List, NoReturn, Sequence, Any, Dict, Tuple, TextIO, overload, Optional, - Union, TypeVar, Callable, Type, + Union, TypeVar, Callable, Type ) import sys -from types import FrameType, TracebackType +from types import FrameType, ModuleType, TracebackType + +if sys.version_info >= (3, 3): + from importlib.abc import MetaPathFinder +else: + MetaPathFinder = Any _T = TypeVar('_T') # ----- sys variables ----- -abiflags = ... # type: str -argv = ... # type: List[str] +abiflags: str +argv: List[str] base_exec_prefix: str base_prefix: str -byteorder = ... # type: str -builtin_module_names = ... # type: Sequence[str] # actually a tuple of strings -copyright = ... # type: str +byteorder: str +builtin_module_names: Sequence[str] # actually a tuple of strings +copyright: str # dllhandle = 0 # Windows only dont_write_bytecode: bool -__displayhook__ = ... # type: Any # contains the original value of displayhook -__excepthook__ = ... # type: Any # contains the original value of excepthook -exec_prefix = ... # type: str -executable = ... # type: str -float_repr_style = ... # type: str +__displayhook__: Any # contains the original value of displayhook +__excepthook__: Any # contains the original value of excepthook +exec_prefix: str +executable: str +float_repr_style: str hexversion: int -last_type = ... # type: Any -last_value = ... # type: Any -last_traceback = ... # type: Any +last_type: Optional[Type[BaseException]] +last_value: Optional[BaseException] +last_traceback: Optional[TracebackType] maxsize: int maxunicode: int -meta_path = ... # type: List[Any] -modules = ... # type: Dict[str, Any] -path = ... # type: List[str] -path_hooks = ... # type: List[Any] # TODO precise type; function, path to finder -path_importer_cache = ... # type: Dict[str, Any] # TODO precise type -platform = ... # type: str -prefix = ... # type: str -ps1 = ... # type: str -ps2 = ... # type: str -stdin = ... # type: TextIO -stdout = ... # type: TextIO -stderr = ... # type: TextIO -__stdin__ = ... # type: TextIO -__stdout__ = ... # type: TextIO -__stderr__ = ... # type: TextIO +meta_path: List[MetaPathFinder] +modules: Dict[str, ModuleType] +path: List[str] +path_hooks: List[Any] # TODO precise type; function, path to finder +path_importer_cache: Dict[str, Any] # TODO precise type +platform: str +prefix: str +ps1: str +ps2: str +stdin: TextIO +stdout: TextIO +stderr: TextIO +__stdin__: TextIO +__stdout__: TextIO +__stderr__: TextIO # deprecated and removed in Python 3.3: -subversion = ... # type: Tuple[str, str, str] -tracebacklimit = 0 -version = ... # type: str -api_version = 0 -warnoptions = ... # type: Any +subversion: Tuple[str, str, str] +tracebacklimit: int +version: str +api_version: int +warnoptions: Any # Each entry is a tuple of the form (action, message, category, module, # lineno) # winver = '' # Windows only -_xoptions = ... # type: Dict[Any, Any] +_xoptions: Dict[Any, Any] -flags = ... # type: _flags + +flags: _flags class _flags: - debug = 0 - division_warning = 0 - inspect = 0 - interactive = 0 - optimize = 0 - dont_write_bytecode = 0 - no_user_site = 0 - no_site = 0 - ignore_environment = 0 - verbose = 0 - bytes_warning = 0 - quiet = 0 - hash_randomization = 0 + debug: int + division_warning: int + inspect: int + interactive: int + optimize: int + dont_write_bytecode: int + no_user_site: int + no_site: int + ignore_environment: int + verbose: int + bytes_warning: int + quiet: int + hash_randomization: int if sys.version_info >= (3, 7): dev_mode: int -float_info = ... # type: _float_info +float_info: _float_info class _float_info: - epsilon = 0.0 # DBL_EPSILON - dig = 0 # DBL_DIG - mant_dig = 0 # DBL_MANT_DIG - max = 0.0 # DBL_MAX - max_exp = 0 # DBL_MAX_EXP - max_10_exp = 0 # DBL_MAX_10_EXP - min = 0.0 # DBL_MIN - min_exp = 0 # DBL_MIN_EXP - min_10_exp = 0 # DBL_MIN_10_EXP - radix = 0 # FLT_RADIX - rounds = 0 # FLT_ROUNDS + epsilon: float # DBL_EPSILON + dig: int # DBL_DIG + mant_dig: int # DBL_MANT_DIG + max: float # DBL_MAX + max_exp: int # DBL_MAX_EXP + max_10_exp: int # DBL_MAX_10_EXP + min: float # DBL_MIN + min_exp: int # DBL_MIN_EXP + min_10_exp: int # DBL_MIN_10_EXP + radix: int # FLT_RADIX + rounds: int # FLT_ROUNDS -hash_info = ... # type: _hash_info +hash_info: _hash_info class _hash_info: - width = 0 - modulus = 0 - inf = 0 - nan = 0 - imag = 0 + width: int + modulus: int + inf: int + nan: int + imag: int -int_info = ... # type: _int_info +implementation: _implementation +class _implementation: + name: str + version: _version_info + hexversion: int + cache_tag: str + +int_info: _int_info class _int_info: - bits_per_digit = 0 - sizeof_digit = 0 + bits_per_digit: int + sizeof_digit: int class _version_info(Tuple[int, int, int, str, int]): - major = 0 - minor = 0 - micro = 0 - releaselevel = ... # type: str - serial = 0 -version_info = ... # type: _version_info + major: int + minor: int + micro: int + releaselevel: str + serial: int +version_info: _version_info def call_tracing(fn: Callable[..., _T], args: Any) -> _T: ... def _clear_type_cache() -> None: ... @@ -118,7 +131,6 @@ def _current_frames() -> Dict[int, Any]: ... def displayhook(value: Optional[int]) -> None: ... def excepthook(type_: Type[BaseException], value: BaseException, traceback: TracebackType) -> None: ... -# TODO should be a union of tuple, see mypy#1178 def exc_info() -> Tuple[Optional[Type[BaseException]], Optional[BaseException], Optional[TracebackType]]: ... @@ -152,7 +164,23 @@ _TraceFunc = Callable[[FrameType, str, Any], Optional[Callable[[FrameType, str, def gettrace() -> Optional[_TraceFunc]: ... def settrace(tracefunc: _TraceFunc) -> None: ... -def getwindowsversion() -> Any: ... # Windows only, TODO return type + +class _WinVersion(Tuple[int, int, int, int, + str, int, int, int, int, + Tuple[int, int, int]]): + major: int + minor: int + build: int + platform: int + service_pack: str + service_pack_minor: int + service_pack_major: int + suite_mast: int + product_type: int + platform_version: Tuple[int, int, int] + + +def getwindowsversion() -> _WinVersion: ... # Windows only def intern(string: str) -> str: ... if sys.version_info >= (3, 5):