Improve threading (#403)

* initial stubgen

* comment everything

* 17.1.0 done

* 17.1.1 done

* 17.1.2 done

* 17.1.3 done

* 17.1.4 done

* 17.1.5 done

* reorder __enter__, __exit__

* 17.1.6 done

* 17.1.7 done

* 17.1.8 done

* 17.1.9 done

* cleanup, py3 done

* py2 begin, comment everything

* 16.2.0 done

* 16.2.1 done

* 16.2.2 done

* 16.2.3 done

* 16.2.4 done

* 16.2.5 done

* 16.2.6 done

* 16.2.7 done

* cleanup, py2 done

* remove old threading stubs

* use --strict-optional

* improve Condition.wait_for

* remove type ignore
This commit is contained in:
Valérian Rousset
2016-08-01 23:31:57 +02:00
committed by Matthias Kramm
parent 4c20cd6711
commit ee02a8a968
3 changed files with 179 additions and 164 deletions

View File

@@ -1,95 +0,0 @@
# Stubs for threading
from typing import Any, Optional, Callable, TypeVar, Union, List, Mapping, Sequence
def active_count() -> int: ...
def activeCount() -> int: ...
def current_thread() -> Thread: ...
def currentThread() -> Thread: ...
def enumerate() -> List[Thread]: ...
class Thread(object):
name = ... # type: str
ident = ... # type: Optional[int]
daemon = ... # type: bool
def __init__(self, group: Any = ..., target: Callable[..., Any] = ...,
name: str = ..., args: Sequence[Any] = ...,
kwargs: Mapping[str, Any] = ...) -> None: ...
def start(self) -> None: ...
def run(self) -> None: ...
def join(self, timeout: float = ...) -> None: ...
def is_alive(self) -> bool: ...
# Legacy methods
def isAlive(self) -> bool: ...
def getName(self) -> str: ...
def setName(self, name: str) -> None: ...
def isDaemon(self) -> bool: ...
def setDaemon(self, daemon: bool) -> None: ...
class Timer(Thread):
def __init__(self, interval: float, function: Callable[..., Any],
args: Sequence[Any] = ...,
kwargs: Mapping[str, Any] = ...) -> None: ...
def cancel(self) -> None : ...
# TODO: better type
def settrace(func: Callable[[Any, str, Any], Any]) -> None: ...
def setprofile(func: Any) -> None: ...
def stack_size(size: int = ...) -> None: ...
class ThreadError(Exception):
pass
class local(Any): ...
class Event(object):
def is_set(self) -> bool: ...
def isSet(self) -> bool: ...
def set(self) -> None: ...
def clear(self) -> None: ...
# TODO can it return None?
def wait(self, timeout: float = ...) -> bool: ...
class Lock(object):
def acquire(self, blocking: bool = ...) -> bool: ...
def release(self) -> None: ...
def locked(self) -> bool: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args): ...
class RLock(object):
def acquire(self, blocking: int = ...) -> Optional[bool]: ...
def release(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args): ...
class Semaphore(object):
def acquire(self, blocking: bool = ...) -> Optional[bool]: ...
def release(self) -> None: ...
def __init__(self, value: int = ...) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args): ...
class BoundedSemaphore(Semaphore):
def acquire(self, blocking: bool = ...) -> Optional[bool]: ...
def release(self) -> None: ...
def __init__(self, value: int = ...) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args): ...
_T = TypeVar('_T')
class Condition(object):
def acquire(self, blocking: bool = ...) -> bool: ...
def release(self) -> None: ...
def notify(self, n: int = ...) -> None: ...
def notify_all(self) -> None: ...
def notifyAll(self) -> None: ...
def wait(self, timeout: float = ...) -> bool: ...
def wait_for(self, predicate: Callable[[], _T], timeout: float = ...) -> Union[_T, bool]: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args): ...
def __init__(self, lock: Lock = ...) -> None: ...

179
stdlib/2and3/threading.pyi Normal file
View File

@@ -0,0 +1,179 @@
# Stubs for threading
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')
def active_count() -> int: ...
if sys.version_info < (3,):
def activeCount() -> int: ...
def current_thread() -> Thread: ...
if sys.version_info < (3,):
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: ...
def settrace(func: _TF) -> None: ...
def setprofile(func: _PF) -> None: ...
def stack_size(size: int = ...) -> int: ...
if sys.version_info >= (3,):
TIMEOUT_MAX = ... # type: int
if sys.version_info < (3,):
class ThreadError(Exception): ...
class local: ...
class Thread:
name = ... # type: str
ident = ... # type: Optional[int]
daemon = ... # type: bool
if sys.version_info >= (3,):
def __init__(self, group: None = ...,
target: Optional[Callable[..., None]] = ...,
name: Optional[str] = ...,
args: Tuple[Any, ...] = ...,
kwargs: Mapping[str, Any] = ...,
*, daemon: Optional[bool] = ...) -> None: ...
else:
def __init__(self, group: None = ...,
target: Optional[Callable[..., None]] = ...,
name: Optional[str] = ...,
args: Tuple[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: ...
def is_alive(self) -> bool: ...
if sys.version_info < (3,):
def isAlive(self) -> bool: ...
def isDaemon(self) -> bool: ...
def setDaemon(self, daemonic: bool) -> None: ...
class Lock:
def __init__(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[Exception],
exc_tb: Optional[TracebackType]) -> bool: ...
if sys.version_info >= (3,):
def acquire(self, blocking: bool = ..., timeout: int = ...) -> bool: ...
else:
def acquire(self, blocking: bool = ...) -> bool: ...
def release(self) -> None: ...
class RLock:
def __init__(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[Exception],
exc_tb: Optional[TracebackType]) -> bool: ...
if sys.version_info >= (3,):
def acquire(self, blocking: bool = ..., timeout: int = ...) -> bool: ...
else:
def acquire(self, blocking: bool = ...) -> bool: ...
def release(self) -> None: ...
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[Exception],
exc_tb: Optional[TracebackType]) -> bool: ...
if sys.version_info >= (3,):
def acquire(self, blocking: bool = ..., timeout: int = ...) -> 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: ...
class Semaphore:
def __init__(self, value: int = ...) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(self, exc_type: Optional[Type[BaseException]],
exc_val: Optional[Exception],
exc_tb: Optional[TracebackType]) -> bool: ...
if sys.version_info >= (3,):
def acquire(self, blocking: bool = ..., timeout: int = ...) -> 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[Exception],
exc_tb: Optional[TracebackType]) -> bool: ...
if sys.version_info >= (3,):
def acquire(self, blocking: bool = ..., timeout: int = ...) -> 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: ...
class Timer(Thread):
if sys.version_info >= (3,):
def __init__(self, interval: float, function: Callable[..., None],
args: Optional[List[Any]] = ...,
kwargs: Optional[Mapping[str, Any]] = ...) -> None: ...
else:
def __init__(self, interval: float, function: Callable[..., None],
args: List[Any] = ...,
kwargs: Mapping[str, Any] = ...) -> None: ...
def cancel(self) -> None: ...
if sys.version_info >= (3,):
class Barrier:
parties = ... # type: int
n_waiting = ... # type: int
broken = ... # type: 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): ...

View File

@@ -1,69 +0,0 @@
# Stubs for threading
# NOTE: These are incomplete!
from typing import Any, Optional, Callable, TypeVar, Union, Mapping, Sequence, List
class Thread:
name = ... # type: str
ident = 0
daemon = False
def __init__(self, group: Any = ..., target: Callable[..., Any] = ...,
name: str = ..., args: Sequence[Any] = ...,
kwargs: Mapping[str, Any] = ..., daemon: bool = ...) -> None: ...
def start(self) -> None: ...
def run(self) -> None: ...
def join(self, timeout: float = ...) -> None: ...
def is_alive(self) -> bool: ...
# Legacy methods
def getName(self) -> str: ...
def setName(self, name: str) -> None: ...
def isDaemon(self) -> bool: ...
def setDaemon(self, daemon: bool) -> None: ...
class Timer(Thread):
def __init__(self, interval: float, function: Callable[..., Any],
args: Sequence[Any] = ...,
kwargs: Mapping[str, Any] = ...) -> None: ...
def cancel(self) -> None : ...
class local(Any): ...
class Event:
def is_set(self) -> bool: ...
def set(self) -> None: ...
def clear(self) -> None: ...
# TODO can it return None?
def wait(self, timeout: float = ...) -> bool: ...
class Lock:
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
def release(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args): ...
class RLock:
def acquire(self, blocking: bool = ...,
timeout: float = ...) -> Optional[bool]: ...
def release(self) -> None: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args): ...
_T = TypeVar('_T')
class Condition:
def acquire(self, blocking: bool = ..., timeout: float = ...) -> bool: ...
def release(self) -> None: ...
def notify(self, n: int = ...) -> None: ...
def notify_all(self) -> None: ...
def wait(self, timeout: float = ...) -> bool: ...
def wait_for(self, predicate: Callable[[], _T], timeout: float = ...) -> Union[_T, bool]: ...
def __enter__(self) -> bool: ...
def __exit__(self, *args): ...
def current_thread() -> Thread: ...
def active_count() -> int: ...
def enumerate() -> List[Thread]: ...
def main_thread() -> Thread: ...