complete and merge weakref stubs (#1343)

This commit is contained in:
Jelle Zijlstra
2017-05-24 20:35:16 -07:00
committed by Guido van Rossum
parent 383d1dc9e1
commit 875b02e374
6 changed files with 160 additions and 181 deletions

View File

@@ -1,21 +0,0 @@
from typing import Any, Callable, Generic, Optional, TypeVar
_T = TypeVar('_T')
class CallableProxyType(object): # "weakcallableproxy"
pass
class ProxyType(object): # "weakproxy"
pass
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
def getweakrefcount(object: Any) -> int: ...
def getweakrefs(object: Any) -> int: ...
def proxy(object: Any, callback: Callable[[Any], Any] = ...) -> None: ...

View File

@@ -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, ...

View File

@@ -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): ...