Format: application/octet-stream
⬇ Download File (4.3 KB)
   1  import sys
   2  import types
   3  from _weakrefset import WeakSet as WeakSet
   4  from typing import (
   5      Any,
   6      Callable,
   7      Dict,
   8      Generic,
   9      Iterable,
  10      Iterator,
  11      List,
  12      Mapping,
  13      MutableMapping,
  14      Optional,
  15      Tuple,
  16      Type,
  17      TypeVar,
  18      Union,
  19      overload,
  20  )
  21  
  22  from _weakref import (
  23      CallableProxyType as CallableProxyType,
  24      ProxyType as ProxyType,
  25      ReferenceType as ReferenceType,
  26      getweakrefcount as getweakrefcount,
  27      getweakrefs as getweakrefs,
  28      proxy as proxy,
  29      ref as ref,
  30  )
  31  
  32  if sys.version_info < (3, 0):
  33      from exceptions import ReferenceError as ReferenceError
  34  
  35  _S = TypeVar("_S")
  36  _T = TypeVar("_T")
  37  _KT = TypeVar("_KT")
  38  _VT = TypeVar("_VT")
  39  
  40  ProxyTypes: Tuple[Type[Any], ...]
  41  
  42  if sys.version_info >= (3, 4):
  43      class WeakMethod(ref[types.MethodType]):
  44          def __new__(cls, meth: types.MethodType, callback: Optional[Callable[[types.MethodType], Any]] = ...) -> WeakMethod: ...
  45          def __call__(self) -> Optional[types.MethodType]: ...
  46  
  47  class WeakValueDictionary(MutableMapping[_KT, _VT]):
  48      @overload
  49      def __init__(self) -> None: ...
  50      @overload
  51      def __init__(self, __other: Union[Mapping[_KT, _VT], Iterable[Tuple[_KT, _VT]]], **kwargs: _VT) -> None: ...
  52      def __len__(self) -> int: ...
  53      def __getitem__(self, k: _KT) -> _VT: ...
  54      def __setitem__(self, k: _KT, v: _VT) -> None: ...
  55      def __delitem__(self, v: _KT) -> None: ...
  56      if sys.version_info < (3, 0):
  57          def has_key(self, key: object) -> bool: ...
  58      def __contains__(self, o: object) -> bool: ...
  59      def __iter__(self) -> Iterator[_KT]: ...
  60      def __str__(self) -> str: ...
  61      def copy(self) -> WeakValueDictionary[_KT, _VT]: ...
  62      if sys.version_info < (3, 0):
  63          def keys(self) -> List[_KT]: ...
  64          def values(self) -> List[_VT]: ...
  65          def items(self) -> List[Tuple[_KT, _VT]]: ...
  66          def iterkeys(self) -> Iterator[_KT]: ...
  67          def itervalues(self) -> Iterator[_VT]: ...
  68          def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ...
  69      else:
  70          # These are incompatible with Mapping
  71          def keys(self) -> Iterator[_KT]: ...  # type: ignore
  72          def values(self) -> Iterator[_VT]: ...  # type: ignore
  73          def items(self) -> Iterator[Tuple[_KT, _VT]]: ...  # type: ignore
  74      def itervaluerefs(self) -> Iterator[KeyedRef[_KT, _VT]]: ...
  75      def valuerefs(self) -> List[KeyedRef[_KT, _VT]]: ...
  76  
  77  class KeyedRef(ref[_T], Generic[_KT, _T]):
  78      key: _KT
  79      def __new__(type, ob: _T, callback: Callable[[_T], Any], key: _KT) -> KeyedRef: ...
  80      def __init__(self, ob: _T, callback: Callable[[_T], Any], key: _KT) -> None: ...
  81  
  82  class WeakKeyDictionary(MutableMapping[_KT, _VT]):
  83      @overload
  84      def __init__(self, dict: None = ...) -> None: ...
  85      @overload
  86      def __init__(self, dict: Union[Mapping[_KT, _VT], Iterable[Tuple[_KT, _VT]]]) -> None: ...
  87      def __len__(self) -> int: ...
  88      def __getitem__(self, k: _KT) -> _VT: ...
  89      def __setitem__(self, k: _KT, v: _VT) -> None: ...
  90      def __delitem__(self, v: _KT) -> None: ...
  91      if sys.version_info < (3, 0):
  92          def has_key(self, key: object) -> bool: ...
  93      def __contains__(self, o: object) -> bool: ...
  94      def __iter__(self) -> Iterator[_KT]: ...
  95      def __str__(self) -> str: ...
  96      def copy(self) -> WeakKeyDictionary[_KT, _VT]: ...
  97      if sys.version_info < (3, 0):
  98          def keys(self) -> List[_KT]: ...
  99          def values(self) -> List[_VT]: ...
 100          def items(self) -> List[Tuple[_KT, _VT]]: ...
 101          def iterkeys(self) -> Iterator[_KT]: ...
 102          def itervalues(self) -> Iterator[_VT]: ...
 103          def iteritems(self) -> Iterator[Tuple[_KT, _VT]]: ...
 104          def iterkeyrefs(self) -> Iterator[ref[_KT]]: ...
 105      else:
 106          # These are incompatible with Mapping
 107          def keys(self) -> Iterator[_KT]: ...  # type: ignore
 108          def values(self) -> Iterator[_VT]: ...  # type: ignore
 109          def items(self) -> Iterator[Tuple[_KT, _VT]]: ...  # type: ignore
 110      def keyrefs(self) -> List[ref[_KT]]: ...
 111  
 112  if sys.version_info >= (3, 4):
 113      class finalize:
 114          def __init__(self, __obj: _S, __func: Callable[..., _T], *args: Any, **kwargs: Any) -> None: ...
 115          def __call__(self, _: Any = ...) -> Optional[_T]: ...
 116          def detach(self) -> Optional[Tuple[_S, _T, Tuple[Any, ...], Dict[str, Any]]]: ...
 117          def peek(self) -> Optional[Tuple[_S, _T, Tuple[Any, ...], Dict[str, Any]]]: ...
 118          alive: bool
 119          atexit: bool
 120