From 85afac3bd5198c7a685eca3956cc4a23e70b3424 Mon Sep 17 00:00:00 2001 From: Rune Tynan Date: Sat, 18 Jan 2020 10:42:32 -0500 Subject: [PATCH] Add (_)dummy_threading module, identical to threading (#3554) * Add (_)dummy_threading module, identical to threading * Remove unnecessary comment, add consistency check --- stdlib/2and3/_dummy_threading.pyi | 197 ++++++++++++++++++++++++++++++ stdlib/2and3/dummy_threading.pyi | 3 + stdlib/2and3/threading.pyi | 3 +- tests/check_consistent.py | 1 + 4 files changed, 203 insertions(+), 1 deletion(-) create mode 100644 stdlib/2and3/_dummy_threading.pyi create mode 100644 stdlib/2and3/dummy_threading.pyi diff --git a/stdlib/2and3/_dummy_threading.pyi b/stdlib/2and3/_dummy_threading.pyi new file mode 100644 index 000000000..b10333543 --- /dev/null +++ b/stdlib/2and3/_dummy_threading.pyi @@ -0,0 +1,197 @@ + +from typing import ( + Any, Callable, Iterable, List, Mapping, Optional, Tuple, Type, Union, + TypeVar, +) +from types import FrameType, TracebackType +import sys + +# TODO recursive type +_TF = Callable[[FrameType, str, Any], Optional[Callable[..., Any]]] + +_PF = Callable[[FrameType, str, Any], None] +_T = TypeVar('_T') + + +__all__: List[str] + +def active_count() -> int: ... +if sys.version_info < (3,): + def activeCount() -> int: ... + +def current_thread() -> Thread: ... +def currentThread() -> Thread: ... + +if sys.version_info >= (3,): + def get_ident() -> int: ... + +def enumerate() -> List[Thread]: ... + +if sys.version_info >= (3, 4): + def main_thread() -> Thread: ... + +if sys.version_info >= (3, 8): + from _thread import get_native_id as get_native_id + +def settrace(func: _TF) -> None: ... +def setprofile(func: Optional[_PF]) -> None: ... +def stack_size(size: int = ...) -> int: ... + +if sys.version_info >= (3,): + TIMEOUT_MAX: float + +class ThreadError(Exception): ... + + +class local(object): + def __getattribute__(self, name: str) -> Any: ... + def __setattr__(self, name: str, value: Any) -> None: ... + def __delattr__(self, name: str) -> None: ... + + +class Thread: + name: str + ident: Optional[int] + daemon: bool + if sys.version_info >= (3,): + def __init__(self, group: None = ..., + target: Optional[Callable[..., Any]] = ..., + name: Optional[str] = ..., + args: Iterable[Any] = ..., + kwargs: Mapping[str, Any] = ..., + *, daemon: Optional[bool] = ...) -> None: ... + else: + def __init__(self, group: None = ..., + target: Optional[Callable[..., Any]] = ..., + name: Optional[str] = ..., + args: Iterable[Any] = ..., + kwargs: Mapping[str, Any] = ...) -> None: ... + def start(self) -> None: ... + def run(self) -> None: ... + def join(self, timeout: Optional[float] = ...) -> None: ... + def getName(self) -> str: ... + def setName(self, name: str) -> None: ... + if sys.version_info >= (3, 8): + @property + def native_id(self) -> Optional[int]: ... # only available on some platforms + def is_alive(self) -> bool: ... + def isAlive(self) -> bool: ... + def isDaemon(self) -> bool: ... + def setDaemon(self, daemonic: bool) -> None: ... + + +class _DummyThread(Thread): ... + + +class Lock: + def __init__(self) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + def locked(self) -> bool: ... + + +class _RLock: + def __init__(self) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + + +RLock = _RLock + + +class Condition: + def __init__(self, lock: Union[Lock, _RLock, None] = ...) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> bool: ... + if sys.version_info >= (3,): + def wait_for(self, predicate: Callable[[], _T], + timeout: Optional[float] = ...) -> _T: ... + def notify(self, n: int = ...) -> None: ... + def notify_all(self) -> None: ... + def notifyAll(self) -> None: ... + + +class Semaphore: + def __init__(self, value: int = ...) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + +class BoundedSemaphore: + def __init__(self, value: int = ...) -> None: ... + def __enter__(self) -> bool: ... + def __exit__(self, exc_type: Optional[Type[BaseException]], + exc_val: Optional[BaseException], + exc_tb: Optional[TracebackType]) -> Optional[bool]: ... + if sys.version_info >= (3,): + def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ... + else: + def acquire(self, blocking: bool = ...) -> bool: ... + def release(self) -> None: ... + + +class Event: + def __init__(self) -> None: ... + def is_set(self) -> bool: ... + if sys.version_info < (3,): + def isSet(self) -> bool: ... + def set(self) -> None: ... + def clear(self) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> bool: ... + +if sys.version_info >= (3, 8): + from _thread import _ExceptHookArgs as ExceptHookArgs, ExceptHookArgs as _ExceptHookArgs # don't ask + excepthook: Callable[[_ExceptHookArgs], Any] + +class Timer(Thread): + if sys.version_info >= (3,): + def __init__(self, interval: float, function: Callable[..., None], + args: Optional[Iterable[Any]] = ..., + kwargs: Optional[Mapping[str, Any]] = ...) -> None: ... + else: + def __init__(self, interval: float, function: Callable[..., None], + args: Iterable[Any] = ..., + kwargs: Mapping[str, Any] = ...) -> None: ... + def cancel(self) -> None: ... + + +if sys.version_info >= (3,): + class Barrier: + parties: int + n_waiting: int + broken: bool + def __init__(self, parties: int, action: Optional[Callable[[], None]] = ..., + timeout: Optional[float] = ...) -> None: ... + def wait(self, timeout: Optional[float] = ...) -> int: ... + def reset(self) -> None: ... + def abort(self) -> None: ... + + class BrokenBarrierError(RuntimeError): ... diff --git a/stdlib/2and3/dummy_threading.pyi b/stdlib/2and3/dummy_threading.pyi new file mode 100644 index 000000000..d7d12bb70 --- /dev/null +++ b/stdlib/2and3/dummy_threading.pyi @@ -0,0 +1,3 @@ + +from _dummy_threading import * +from _dummy_threading import __all__ as __all__ diff --git a/stdlib/2and3/threading.pyi b/stdlib/2and3/threading.pyi index ca1b0fd20..b10333543 100644 --- a/stdlib/2and3/threading.pyi +++ b/stdlib/2and3/threading.pyi @@ -1,4 +1,3 @@ -# Stubs for threading from typing import ( Any, Callable, Iterable, List, Mapping, Optional, Tuple, Type, Union, @@ -14,6 +13,8 @@ _PF = Callable[[FrameType, str, Any], None] _T = TypeVar('_T') +__all__: List[str] + def active_count() -> int: ... if sys.version_info < (3,): def activeCount() -> int: ... diff --git a/tests/check_consistent.py b/tests/check_consistent.py index 12659db04..2320e813f 100755 --- a/tests/check_consistent.py +++ b/tests/check_consistent.py @@ -28,6 +28,7 @@ consistent_files = [ {'stdlib/3.7/contextvars.pyi', 'third_party/3/contextvars.pyi'}, {'stdlib/3/ipaddress.pyi', 'third_party/2/ipaddress.pyi'}, {'stdlib/2/copy_reg.pyi', 'stdlib/3/copyreg.pyi'}, + {'stdlib/2and3/threading.pyi', 'stdlib/2and3/_dummy_threading.pyi'} ] def main():