diff --git a/stdlib/2/_weakrefset.pyi b/stdlib/2/_weakrefset.pyi deleted file mode 100644 index 27aade6a6..000000000 --- a/stdlib/2/_weakrefset.pyi +++ /dev/null @@ -1,14 +0,0 @@ -from typing import Iterator, Any, Iterable, MutableSet, TypeVar, Generic - -_T = TypeVar('_T') - -class WeakSet(MutableSet[_T], Generic[_T]): - def __init__(self, data: Iterable[_T] = ...) -> None: ... - - def add(self, x: _T) -> None: ... - def discard(self, x: _T) -> None: ... - def __contains__(self, x: Any) -> bool: ... - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[_T]: ... - - # TODO: difference, difference_update, ... diff --git a/stdlib/2/weakref.pyi b/stdlib/2/weakref.pyi deleted file mode 100644 index f6ad8946f..000000000 --- a/stdlib/2/weakref.pyi +++ /dev/null @@ -1,43 +0,0 @@ -from typing import Any, MutableMapping, Generic, Iterator, List, TypeVar -from _weakref import (getweakrefcount, getweakrefs, ref, proxy, - CallableProxyType, ProxyType, ReferenceType) -from _weakrefset import WeakSet - -ProxyTypes = ... # type: Any - -_KT = TypeVar('_KT') -_VT = TypeVar('_VT') - -# Don't inherit from typing.Dict since -# isinstance(weakref.WeakValueDictionary(), dict) is False -class WeakValueDictionary(MutableMapping[_KT, _VT], Generic[_KT, _VT]): - def itervaluerefs(self) -> Iterator[ReferenceType[_VT]]: ... - def valuerefs(self) -> List[ReferenceType[_VT]]: ... - - def __setitem__(self, k: _KT, v: _VT) -> None: ... - def __delitem__(self, v: _KT) -> None: ... - def __getitem__(self, k: _KT) -> _VT: ... - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[_KT]: ... - - def has_key(self, key: _KT) -> bool: ... - def copy(self) -> WeakValueDictionary[_KT, _VT]: ... - -class WeakKeyDictionary(MutableMapping[_KT, _VT], Generic[_KT, _VT]): - def iterkeyrefs(self) -> Iterator[ReferenceType[_KT]]: ... - def keyrefs(self) -> List[ReferenceType[_KT]]: ... - - def __setitem__(self, k: _KT, v: _VT) -> None: ... - def __delitem__(self, v: _KT) -> None: ... - def __getitem__(self, k: _KT) -> _VT: ... - def __len__(self) -> int: ... - def __iter__(self) -> Iterator[_KT]: ... - - def has_key(self, key: _KT) -> bool: ... - def copy(self) -> WeakKeyDictionary[_KT, _VT]: ... - -# TODO: make generic -class KeyedRef(ReferenceType): - key = ... # type: Any - def __new__(type, ob, callback, key): ... - def __init__(self, ob, callback, key): ... diff --git a/stdlib/2/_weakref.pyi b/stdlib/2and3/_weakref.pyi similarity index 62% rename from stdlib/2/_weakref.pyi rename to stdlib/2and3/_weakref.pyi index a7bb9ea06..76c97df54 100644 --- a/stdlib/2/_weakref.pyi +++ b/stdlib/2and3/_weakref.pyi @@ -1,21 +1,24 @@ +import sys from typing import Any, Callable, Generic, Optional, TypeVar _T = TypeVar('_T') class CallableProxyType(object): # "weakcallableproxy" - pass + def __getattr__(self, attr: str) -> Any: ... class ProxyType(object): # "weakproxy" - pass + def __getattr__(self, attr: str) -> Any: ... class ReferenceType(Generic[_T]): - # TODO rest of members + if sys.version_info >= (3, 4): + __callback__: Callable[[ReferenceType[_T]], Any] def __init__(self, o: _T, callback: Callable[[ReferenceType[_T]], Any] = ...) -> None: ... def __call__(self) -> Optional[_T]: ... + def __hash__(self) -> int: ... ref = ReferenceType def getweakrefcount(object: Any) -> int: ... def getweakrefs(object: Any) -> int: ... -def proxy(object: Any, callback: Callable[[Any], Any] = ...) -> None: ... +def proxy(object: _T, callback: Callable[[_T], Any] = ...) -> ref[_T]: ... diff --git a/stdlib/2and3/_weakrefset.pyi b/stdlib/2and3/_weakrefset.pyi new file mode 100644 index 000000000..950d3fe64 --- /dev/null +++ b/stdlib/2and3/_weakrefset.pyi @@ -0,0 +1,43 @@ +from typing import Iterator, Any, Iterable, MutableSet, Optional, TypeVar, Generic, Union + +_S = TypeVar('_S') +_T = TypeVar('_T') +_SelfT = TypeVar('_SelfT', bound=WeakSet) + +class WeakSet(MutableSet[_T], Generic[_T]): + def __init__(self, data: Optional[Iterable[_T]] = ...) -> None: ... + + def add(self, item: _T) -> None: ... + def clear(self) -> None: ... + def discard(self, item: _T) -> None: ... + def copy(self: _SelfT) -> _SelfT: ... + def pop(self) -> _T: ... + def remove(self, item: _T) -> None: ... + def update(self, other: Iterable[_T]) -> None: ... + def __contains__(self, item: object) -> bool: ... + def __len__(self) -> int: ... + def __iter__(self) -> Iterator[_T]: ... + + def __ior__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def difference(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def __sub__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def difference_update(self: _SelfT, other: Iterable[_T]) -> None: ... + def __isub__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def intersection(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def __and__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def intersection_update(self, other: Iterable[_T]) -> None: ... + def __iand__(self: _SelfT, other: Iterable[_T]) -> _SelfT: ... + def issubset(self, other: Iterable[_T]) -> bool: ... + def __le__(self, other: Iterable[_T]) -> bool: ... + def __lt__(self, other: Iterable[_T]) -> bool: ... + def issuperset(self, other: Iterable[_T]) -> bool: ... + def __ge__(self, other: Iterable[_T]) -> bool: ... + def __gt__(self, other: Iterable[_T]) -> bool: ... + def __eq__(self, other: object) -> bool: ... + def symmetric_difference(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def __xor__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def symmetric_difference_update(self, other: Iterable[_S]) -> None: ... + def __ixor__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def union(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def __or__(self, other: Iterable[_S]) -> WeakSet[Union[_S, _T]]: ... + def isdisjoint(self, other: Iterable[_T]) -> bool: ... diff --git a/stdlib/2and3/weakref.pyi b/stdlib/2and3/weakref.pyi new file mode 100644 index 000000000..e3ddbf278 --- /dev/null +++ b/stdlib/2and3/weakref.pyi @@ -0,0 +1,110 @@ +import sys +import types +from typing import ( + TypeVar, Generic, Any, Callable, overload, Mapping, Iterator, Tuple, + Iterable, Optional, Type, MutableMapping, Union, List, Dict +) + +from _weakref import ( + getweakrefcount as getweakrefcount, + getweakrefs as getweakrefs, + ref as ref, + proxy as proxy, + CallableProxyType as CallableProxyType, + ProxyType as ProxyType, + ReferenceType as ReferenceType) +from _weakrefset import WeakSet as WeakSet + +if sys.version_info < (3, 0): + from exceptions import ReferenceError as ReferenceError + +_S = TypeVar('_S') +_T = TypeVar('_T') +_KT = TypeVar('_KT') +_VT = TypeVar('_VT') + +ProxyTypes: Tuple[Type[Any], ...] + +if sys.version_info >= (3, 4): + class WeakMethod(ref[types.MethodType]): + def __new__(cls, meth: types.MethodType, callback: Optional[Callable[[types.MethodType], Any]] = ...) -> WeakMethod: ... + def __call__(self) -> Optional[types.MethodType]: ... + +class WeakValueDictionary(MutableMapping[_KT, _VT]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, __map: Union[Mapping[_KT, _VT], Iterable[Tuple[_KT, _VT]]], **kwargs: _VT) -> None: ... + + def __len__(self) -> int: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __setitem__(self, k: _KT, v: _VT) -> None: ... + def __delitem__(self, v: _KT) -> None: ... + if sys.version_info < (3, 0): + def has_key(self, key: object) -> bool: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_KT]: ... + def __str__(self) -> str: ... + + def copy(self) -> WeakValueDictionary[_KT, _VT]: ... + + if sys.version_info < (3, 0): + def keys(self) -> List[_KT]: ... + def values(self) -> List[_VT]: ... + def items(self) -> List[Tuple[_KT, _VT]]: ... + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + else: + # These are incompatible with Mapping + def keys(self) -> Iterator[_KT]: ... # type: ignore + def values(self) -> Iterator[_VT]: ... # type: ignore + def items(self) -> Iterator[Tuple[_KT, _VT]]: ... # type: ignore + def itervaluerefs(self) -> Iterator[KeyedRef[_KT, _VT]]: ... + def valuerefs(self) -> List[KeyedRef[_KT, _VT]]: ... + +class KeyedRef(ref[_T], Generic[_KT, _T]): + key: _KT + def __init__(self, ob: _T, callback: Callable[[_T], Any], key: _KT) -> None: ... + +class WeakKeyDictionary(MutableMapping[_KT, _VT]): + @overload + def __init__(self) -> None: ... + @overload + def __init__(self, __map: Union[Mapping[_KT, _VT], Iterable[Tuple[_KT, _VT]]], **kwargs: _VT) -> None: ... + + def __len__(self) -> int: ... + def __getitem__(self, k: _KT) -> _VT: ... + def __setitem__(self, k: _KT, v: _VT) -> None: ... + def __delitem__(self, v: _KT) -> None: ... + if sys.version_info < (3, 0): + def has_key(self, key: object) -> bool: ... + def __contains__(self, o: object) -> bool: ... + def __iter__(self) -> Iterator[_KT]: ... + def __str__(self) -> str: ... + + def copy(self) -> WeakKeyDictionary[_KT, _VT]: ... + + if sys.version_info < (3, 0): + def keys(self) -> List[_KT]: ... + def values(self) -> List[_VT]: ... + def items(self) -> List[Tuple[_KT, _VT]]: ... + def iterkeys(self) -> Iterator[_KT]: ... + def itervalues(self) -> Iterator[_VT]: ... + def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ... + def iterkeyrefs(self) -> Iterator[ref[_KT]]: ... + else: + # These are incompatible with Mapping + def keys(self) -> Iterator[_KT]: ... # type: ignore + def values(self) -> Iterator[_VT]: ... # type: ignore + def items(self) -> Iterator[Tuple[_KT, _VT]]: ... # type: ignore + def keyrefs(self) -> List[ref[_KT]]: ... + +if sys.version_info >= (3, 4): + class finalize: + def __init__(self, obj: _S, func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ... + def __call__(self, _: Any = ...) -> Optional[_T]: ... + def detach(self) -> Optional[Tuple[_S, _T, Tuple[Any, ...], Dict[str, Any]]]: ... + def peek(self) -> Optional[Tuple[_S, _T, Tuple[Any, ...], Dict[str, Any]]]: ... + alive: bool + atexit: bool diff --git a/stdlib/3/weakref.pyi b/stdlib/3/weakref.pyi deleted file mode 100644 index 6c4981ac1..000000000 --- a/stdlib/3/weakref.pyi +++ /dev/null @@ -1,120 +0,0 @@ -# Stubs for weakref - -# NOTE: These are incomplete! - -from typing import ( - TypeVar, Generic, Any, Callable, overload, Mapping, Iterator, Dict, Tuple, - Iterable, Optional -) - -_T = TypeVar('_T') -_KT = TypeVar('_KT') -_VT = TypeVar('_VT') - -class ReferenceType(Generic[_T]): - # TODO rest of members - def __init__(self, o: _T, callback: Callable[[ReferenceType[_T]], - Any] = ...) -> None: ... - def __call__(self) -> Optional[_T]: ... - -ref = ReferenceType - -# TODO callback -def proxy(object: _T) -> _T: ... - -class WeakValueDictionary(Generic[_KT, _VT]): - # TODO tuple iterable argument? - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, map: Mapping[_KT, _VT]) -> None: ... - - def __len__(self) -> int: ... - def __getitem__(self, k: _KT) -> _VT: ... - def __setitem__(self, k: _KT, v: _VT) -> None: ... - def __delitem__(self, v: _KT) -> None: ... - def __contains__(self, o: object) -> bool: ... - def __iter__(self) -> Iterator[_KT]: ... - def __str__(self) -> str: ... - - def clear(self) -> None: ... - def copy(self) -> Dict[_KT, _VT]: ... - - @overload - def get(self, k: _KT) -> _VT: ... - @overload - def get(self, k: _KT, default: _VT) -> _VT: ... - - @overload - def pop(self, k: _KT) -> _VT: ... - @overload - def pop(self, k: _KT, default: _VT) -> _VT: ... - - def popitem(self) -> Tuple[_KT, _VT]: ... - - @overload - def setdefault(self, k: _KT) -> _VT: ... - @overload - def setdefault(self, k: _KT, default: _VT) -> _VT: ... - - @overload - def update(self, m: Mapping[_KT, _VT]) -> None: ... - @overload - def update(self, m: Iterable[Tuple[_KT, _VT]]) -> None: ... - - # NOTE: incompatible with Mapping - def keys(self) -> Iterator[_KT]: ... - def values(self) -> Iterator[_VT]: ... - def items(self) -> Iterator[Tuple[_KT, _VT]]: ... - - # TODO return type - def valuerefs(self) -> Iterable[Any]: ... - - -class WeakKeyDictionary(Generic[_KT, _VT]): - # TODO tuple iterable argument? - @overload - def __init__(self) -> None: ... - @overload - def __init__(self, map: Mapping[_KT, _VT]) -> None: ... - - def __len__(self) -> int: ... - def __getitem__(self, k: _KT) -> _VT: ... - def __setitem__(self, k: _KT, v: _VT) -> None: ... - def __delitem__(self, v: _KT) -> None: ... - def __contains__(self, o: object) -> bool: ... - def __iter__(self) -> Iterator[_KT]: ... - def __str__(self) -> str: ... - - def clear(self) -> None: ... - def copy(self) -> Dict[_KT, _VT]: ... - - @overload - def get(self, k: _KT) -> _VT: ... - @overload - def get(self, k: _KT, default: _VT) -> _VT: ... - - @overload - def pop(self, k: _KT) -> _VT: ... - @overload - def pop(self, k: _KT, default: _VT) -> _VT: ... - - def popitem(self) -> Tuple[_KT, _VT]: ... - - @overload - def setdefault(self, k: _KT) -> _VT: ... - @overload - def setdefault(self, k: _KT, default: _VT) -> _VT: ... - - @overload - def update(self, m: Mapping[_KT, _VT]) -> None: ... - @overload - def update(self, m: Iterable[Tuple[_KT, _VT]]) -> None: ... - - # NOTE: incompatible with Mapping - def keys(self) -> Iterator[_KT]: ... - def values(self) -> Iterator[_VT]: ... - def items(self) -> Iterator[Tuple[_KT, _VT]]: ... - - # TODO return type - def valuerefs(self) -> Iterable[Any]: ...