| 1 |
from _typeshed import SupportsKeysAndGetItem |
| 2 |
from _weakref import getweakrefcount as getweakrefcount, getweakrefs as getweakrefs, proxy as proxy |
| 3 |
from _weakrefset import WeakSet as WeakSet |
| 4 |
from collections.abc import Callable, Iterable, Iterator, Mapping, MutableMapping |
| 5 |
from types import GenericAlias |
| 6 |
from typing import Any, ClassVar, Generic, TypeVar, final, overload |
| 7 |
from typing_extensions import ParamSpec, Self, disjoint_base |
| 8 |
|
| 9 |
__all__ = [ |
| 10 |
"ref", |
| 11 |
"proxy", |
| 12 |
"getweakrefcount", |
| 13 |
"getweakrefs", |
| 14 |
"WeakKeyDictionary", |
| 15 |
"ReferenceType", |
| 16 |
"ProxyType", |
| 17 |
"CallableProxyType", |
| 18 |
"ProxyTypes", |
| 19 |
"WeakValueDictionary", |
| 20 |
"WeakSet", |
| 21 |
"WeakMethod", |
| 22 |
"finalize", |
| 23 |
] |
| 24 |
|
| 25 |
_T = TypeVar("_T") |
| 26 |
_T1 = TypeVar("_T1") |
| 27 |
_T2 = TypeVar("_T2") |
| 28 |
_KT = TypeVar("_KT") |
| 29 |
_VT = TypeVar("_VT") |
| 30 |
_CallableT = TypeVar("_CallableT", bound=Callable[..., Any]) |
| 31 |
_P = ParamSpec("_P") |
| 32 |
|
| 33 |
ProxyTypes: tuple[type[Any], ...] |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
@final |
| 43 |
class CallableProxyType(Generic[_CallableT]): |
| 44 |
def __eq__(self, value: object, /) -> bool: ... |
| 45 |
def __getattr__(self, attr: str) -> Any: ... |
| 46 |
__call__: _CallableT |
| 47 |
__hash__: ClassVar[None] |
| 48 |
|
| 49 |
@final |
| 50 |
class ProxyType(Generic[_T]): |
| 51 |
def __eq__(self, value: object, /) -> bool: ... |
| 52 |
def __getattr__(self, attr: str) -> Any: ... |
| 53 |
__hash__: ClassVar[None] |
| 54 |
|
| 55 |
@disjoint_base |
| 56 |
class ReferenceType(Generic[_T]): |
| 57 |
__callback__: Callable[[Self], Any] |
| 58 |
def __new__(cls, o: _T, callback: Callable[[Self], Any] | None = ..., /) -> Self: ... |
| 59 |
def __call__(self) -> _T | None: ... |
| 60 |
def __eq__(self, value: object, /) -> bool: ... |
| 61 |
def __hash__(self) -> int: ... |
| 62 |
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ... |
| 63 |
|
| 64 |
ref = ReferenceType |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
class WeakMethod(ref[_CallableT]): |
| 69 |
__slots__ = ("_func_ref", "_meth_type", "_alive", "__weakref__") |
| 70 |
def __new__(cls, meth: _CallableT, callback: Callable[[Self], Any] | None = None) -> Self: ... |
| 71 |
def __call__(self) -> _CallableT | None: ... |
| 72 |
def __eq__(self, other: object) -> bool: ... |
| 73 |
def __ne__(self, other: object) -> bool: ... |
| 74 |
def __hash__(self) -> int: ... |
| 75 |
|
| 76 |
class WeakValueDictionary(MutableMapping[_KT, _VT]): |
| 77 |
@overload |
| 78 |
def __init__(self) -> None: ... |
| 79 |
@overload |
| 80 |
def __init__( |
| 81 |
self: WeakValueDictionary[_KT, _VT], |
| 82 |
other: Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]], |
| 83 |
/, |
| 84 |
) -> None: ... |
| 85 |
@overload |
| 86 |
def __init__( |
| 87 |
self: WeakValueDictionary[str, _VT], |
| 88 |
other: Mapping[str, _VT] | Iterable[tuple[str, _VT]] = (), |
| 89 |
/, |
| 90 |
**kwargs: _VT, |
| 91 |
) -> None: ... |
| 92 |
def __len__(self) -> int: ... |
| 93 |
def __getitem__(self, key: _KT) -> _VT: ... |
| 94 |
def __setitem__(self, key: _KT, value: _VT) -> None: ... |
| 95 |
def __delitem__(self, key: _KT) -> None: ... |
| 96 |
def __contains__(self, key: object) -> bool: ... |
| 97 |
def __iter__(self) -> Iterator[_KT]: ... |
| 98 |
def copy(self) -> WeakValueDictionary[_KT, _VT]: ... |
| 99 |
__copy__ = copy |
| 100 |
def __deepcopy__(self, memo: Any) -> Self: ... |
| 101 |
@overload |
| 102 |
def get(self, key: _KT, default: None = None) -> _VT | None: ... |
| 103 |
@overload |
| 104 |
def get(self, key: _KT, default: _VT) -> _VT: ... |
| 105 |
@overload |
| 106 |
def get(self, key: _KT, default: _T) -> _VT | _T: ... |
| 107 |
|
| 108 |
def keys(self) -> Iterator[_KT]: ... |
| 109 |
def values(self) -> Iterator[_VT]: ... |
| 110 |
def items(self) -> Iterator[tuple[_KT, _VT]]: ... |
| 111 |
def itervaluerefs(self) -> Iterator[KeyedRef[_KT, _VT]]: ... |
| 112 |
def valuerefs(self) -> list[KeyedRef[_KT, _VT]]: ... |
| 113 |
def setdefault(self, key: _KT, default: _VT) -> _VT: ... |
| 114 |
@overload |
| 115 |
def pop(self, key: _KT) -> _VT: ... |
| 116 |
@overload |
| 117 |
def pop(self, key: _KT, default: _VT) -> _VT: ... |
| 118 |
@overload |
| 119 |
def pop(self, key: _KT, default: _T) -> _VT | _T: ... |
| 120 |
@overload |
| 121 |
def update(self, other: SupportsKeysAndGetItem[_KT, _VT], /, **kwargs: _VT) -> None: ... |
| 122 |
@overload |
| 123 |
def update(self, other: Iterable[tuple[_KT, _VT]], /, **kwargs: _VT) -> None: ... |
| 124 |
@overload |
| 125 |
def update(self, other: None = None, /, **kwargs: _VT) -> None: ... |
| 126 |
def __or__(self, other: Mapping[_T1, _T2]) -> WeakValueDictionary[_KT | _T1, _VT | _T2]: ... |
| 127 |
def __ror__(self, other: Mapping[_T1, _T2]) -> WeakValueDictionary[_KT | _T1, _VT | _T2]: ... |
| 128 |
|
| 129 |
@overload |
| 130 |
def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... |
| 131 |
@overload |
| 132 |
def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... |
| 133 |
|
| 134 |
class KeyedRef(ref[_T], Generic[_KT, _T]): |
| 135 |
__slots__ = ("key",) |
| 136 |
key: _KT |
| 137 |
def __new__(type, ob: _T, callback: Callable[[Self], Any], key: _KT) -> Self: ... |
| 138 |
def __init__(self, ob: _T, callback: Callable[[Self], Any], key: _KT) -> None: ... |
| 139 |
|
| 140 |
class WeakKeyDictionary(MutableMapping[_KT, _VT]): |
| 141 |
@overload |
| 142 |
def __init__(self, dict: None = None) -> None: ... |
| 143 |
@overload |
| 144 |
def __init__(self, dict: Mapping[_KT, _VT] | Iterable[tuple[_KT, _VT]]) -> None: ... |
| 145 |
def __len__(self) -> int: ... |
| 146 |
def __getitem__(self, key: _KT) -> _VT: ... |
| 147 |
def __setitem__(self, key: _KT, value: _VT) -> None: ... |
| 148 |
def __delitem__(self, key: _KT) -> None: ... |
| 149 |
def __contains__(self, key: object) -> bool: ... |
| 150 |
def __iter__(self) -> Iterator[_KT]: ... |
| 151 |
def copy(self) -> WeakKeyDictionary[_KT, _VT]: ... |
| 152 |
__copy__ = copy |
| 153 |
def __deepcopy__(self, memo: Any) -> Self: ... |
| 154 |
@overload |
| 155 |
def get(self, key: _KT, default: None = None) -> _VT | None: ... |
| 156 |
@overload |
| 157 |
def get(self, key: _KT, default: _VT) -> _VT: ... |
| 158 |
@overload |
| 159 |
def get(self, key: _KT, default: _T) -> _VT | _T: ... |
| 160 |
|
| 161 |
def keys(self) -> Iterator[_KT]: ... |
| 162 |
def values(self) -> Iterator[_VT]: ... |
| 163 |
def items(self) -> Iterator[tuple[_KT, _VT]]: ... |
| 164 |
def keyrefs(self) -> list[ref[_KT]]: ... |
| 165 |
|
| 166 |
@overload |
| 167 |
def setdefault(self: WeakKeyDictionary[_KT, _VT | None], key: _KT, default: None = None) -> _VT: ... |
| 168 |
@overload |
| 169 |
def setdefault(self, key: _KT, default: _VT) -> _VT: ... |
| 170 |
@overload |
| 171 |
def pop(self, key: _KT) -> _VT: ... |
| 172 |
@overload |
| 173 |
def pop(self, key: _KT, default: _VT) -> _VT: ... |
| 174 |
@overload |
| 175 |
def pop(self, key: _KT, default: _T) -> _VT | _T: ... |
| 176 |
@overload |
| 177 |
def update(self, dict: SupportsKeysAndGetItem[_KT, _VT], /, **kwargs: _VT) -> None: ... |
| 178 |
@overload |
| 179 |
def update(self, dict: Iterable[tuple[_KT, _VT]], /, **kwargs: _VT) -> None: ... |
| 180 |
@overload |
| 181 |
def update(self, dict: None = None, /, **kwargs: _VT) -> None: ... |
| 182 |
def __or__(self, other: Mapping[_T1, _T2]) -> WeakKeyDictionary[_KT | _T1, _VT | _T2]: ... |
| 183 |
def __ror__(self, other: Mapping[_T1, _T2]) -> WeakKeyDictionary[_KT | _T1, _VT | _T2]: ... |
| 184 |
|
| 185 |
@overload |
| 186 |
def __ior__(self, other: SupportsKeysAndGetItem[_KT, _VT]) -> Self: ... |
| 187 |
@overload |
| 188 |
def __ior__(self, other: Iterable[tuple[_KT, _VT]]) -> Self: ... |
| 189 |
|
| 190 |
class finalize(Generic[_P, _T]): |
| 191 |
__slots__ = () |
| 192 |
def __init__(self, obj: _T, func: Callable[_P, Any], /, *args: _P.args, **kwargs: _P.kwargs) -> None: ... |
| 193 |
def __call__(self, _: Any = None) -> Any | None: ... |
| 194 |
def detach(self) -> tuple[_T, Callable[_P, Any], tuple[Any, ...], dict[str, Any]] | None: ... |
| 195 |
def peek(self) -> tuple[_T, Callable[_P, Any], tuple[Any, ...], dict[str, Any]] | None: ... |
| 196 |
@property |
| 197 |
def alive(self) -> bool: ... |
| 198 |
atexit: bool |