From 01d96e4ac49d42d5c5b52bc9d1821fcfad027b30 Mon Sep 17 00:00:00 2001 From: Daniel Shaulov Date: Sat, 16 Jan 2016 00:21:24 +0200 Subject: [PATCH 1/2] Fix signatures of __init__ for Thread and Timer --- stdlib/2.7/threading.pyi | 19 +++++++++---------- stdlib/3/threading.pyi | 19 ++++++++++--------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/stdlib/2.7/threading.pyi b/stdlib/2.7/threading.pyi index 9f8ba5ac8..6342be725 100644 --- a/stdlib/2.7/threading.pyi +++ b/stdlib/2.7/threading.pyi @@ -1,6 +1,6 @@ # Stubs for threading -from typing import Any, Dict, Optional, Callable, TypeVar, Union, List, Mapping +from typing import Any, Optional, Callable, TypeVar, Union, List, Mapping, Sequence def active_count() -> int: ... def activeCount() -> int: ... @@ -14,9 +14,9 @@ class Thread(object): ident = 0 daemon = False - def __init__(self, group: Any = ..., target: Any = ..., - name: str = ..., args: tuple = ..., - kwargs: Dict[Any, Any] = ...) -> None: ... + 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: ... @@ -29,12 +29,11 @@ class Thread(object): def isDaemon(self) -> bool: ... def setDaemon(self, daemon: bool) -> None: ... -class Timer(object): - def __init__(self, interval: float, function: Any, - args: List[Any] = ..., - kwargs: Mapping[Any, Any] = ...) -> None: ... - def cancel(self) -> None: ... - def start(self) -> 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: ... diff --git a/stdlib/3/threading.pyi b/stdlib/3/threading.pyi index a3e2597ba..16523df16 100644 --- a/stdlib/3/threading.pyi +++ b/stdlib/3/threading.pyi @@ -2,16 +2,16 @@ # NOTE: These are incomplete! -from typing import Any, Dict, Optional, Callable, TypeVar, Union +from typing import Any, Optional, Callable, TypeVar, Union, Mapping, Sequence class Thread: name = ... # type: str ident = 0 daemon = False - def __init__(self, group: Any = ..., target: Any = ..., args: Any = ..., - kwargs: Dict[Any, Any] = ..., - verbose: Any = ...) -> None: ... + 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: ... @@ -23,6 +23,12 @@ class Thread: 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 Event: def is_set(self) -> bool: ... def set(self) -> None: ... @@ -54,8 +60,3 @@ class Condition: def wait_for(self, predicate: Callable[[], _T], timeout: float = ...) -> Union[_T, bool]: ... def __enter__(self) -> bool: ... def __exit__(self, *args): ... - -class Timer(Thread): - def __init__(self, interval: float, function: Callable[..., Any], - args: Any = ..., kwargs: Dict[Any, Any] = ...) -> None: ... - def cancel(self) -> None : ... From 14ffe7ea170a209586126049e8cd29758649305e Mon Sep 17 00:00:00 2001 From: Daniel Shaulov Date: Fri, 22 Jan 2016 12:24:36 +0200 Subject: [PATCH 2/2] Inherit from Any in threading.local and SimpleNamespace --- stdlib/2.7/threading.pyi | 6 +----- stdlib/3/threading.pyi | 2 ++ stdlib/3/types.pyi | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/stdlib/2.7/threading.pyi b/stdlib/2.7/threading.pyi index 6342be725..791fa4dde 100644 --- a/stdlib/2.7/threading.pyi +++ b/stdlib/2.7/threading.pyi @@ -43,11 +43,7 @@ def stack_size(size: int = ...) -> None: ... class ThreadError(Exception): pass -class local(object): - # TODO: allows arbitrary parameters... - def __getattr__(self, name: str) -> Any: ... - def __setattr__(self, name: str, value: Any) -> None: ... - def __delattr__(self, name: str) -> None: ... +class local(Any): ... class Event(object): def is_set(self) -> bool: ... diff --git a/stdlib/3/threading.pyi b/stdlib/3/threading.pyi index 16523df16..83f2307ae 100644 --- a/stdlib/3/threading.pyi +++ b/stdlib/3/threading.pyi @@ -29,6 +29,8 @@ class Timer(Thread): kwargs: Mapping[str, Any] = ...) -> None: ... def cancel(self) -> None : ... +class local(Any): ... + class Event: def is_set(self) -> bool: ... def set(self) -> None: ... diff --git a/stdlib/3/types.pyi b/stdlib/3/types.pyi index fbb58d6bc..5e94ee8dd 100644 --- a/stdlib/3/types.pyi +++ b/stdlib/3/types.pyi @@ -67,7 +67,7 @@ class MappingProxyType: def __getitem__(self, key: str) -> Any: ... def __iter__(self) -> Iterator[str]: ... def __len__(self) -> int: ... -class SimpleNamespace: ... +class SimpleNamespace(Any): ... class GeneratorType: gi_code = ... # type: CodeType