Debian Codegraph @

src/frozendict/__init__.pyi

raw
1 from __future__ import annotations
2
3 from typing import (
4 TypeVar,
5 overload,
6 Optional,
7 Union,
8 Any,
9 Dict,
10 Callable,
11 )
12
13 from collections.abc import Hashable
14
15 try:
16 from typing import Mapping, Iterable, Iterator, Tuple, Type
17 except ImportError:
18 from collections.abc import Mapping, Iterable, Iterator
19 Tuple = tuple
20 Type = type
21
22 K = TypeVar("K")
23 V = TypeVar("V", covariant=True)
24 K2 = TypeVar("K2")
25 V2 = TypeVar("V2", covariant=True)
26 SelfT = TypeVar("SelfT", bound=frozendict[K, V])
27
28 # noinspection PyPep8Naming
29 class frozendict(Mapping[K, V]):
30 @overload
31 def __new__(cls: Type[SelfT]) -> SelfT: ...
32 @overload
33 def __new__(cls: Type[SelfT], **kwargs: V) -> frozendict[str, V]: ...
34 @overload
35 def __new__(cls: Type[SelfT], mapping: Mapping[K, V]) -> SelfT: ...
36 @overload
37 def __new__(cls: Type[SelfT], iterable: Iterable[Tuple[K, V]]) -> SelfT: ...
38
39 def __getitem__(self: SelfT, key: K) -> V: ...
40 def __len__(self: SelfT) -> int: ...
41 def __iter__(self: SelfT) -> Iterator[K]: ...
42 def __hash__(self: SelfT) -> int: ...
43 def __reversed__(self: SelfT) -> Iterator[K]: ...
44 def copy(self: SelfT) -> SelfT: ...
45 def __copy__(self: SelfT) -> SelfT: ...
46 def __deepcopy__(self: SelfT) -> SelfT: ...
47 def delete(self: SelfT, key: K) -> SelfT: ...
48 @overload
49 def key(self: SelfT, index: int) -> K: ...
50 @overload
51 def key(self: SelfT) -> K: ...
52 @overload
53 def value(self: SelfT, index: int) -> V: ...
54 @overload
55 def value(self: SelfT) -> V: ...
56 @overload
57 def item(self: SelfT, index: int) -> Tuple[K, V]: ...
58 @overload
59 def item(self: SelfT) -> Tuple[K, V]: ...
60 @overload
61 def __or__(self: SelfT, other: Mapping[K, V]) -> SelfT: ...
62 @overload
63 def __or__(self: SelfT, other: Mapping[K2, V]) -> frozendict[Union[K, K2], V]: ...
64 @overload
65 def __or__(self: SelfT, other: Mapping[K, V2]) -> frozendict[K, Union[V, V2]]: ...
66 @overload
67 def __or__(self: SelfT, other: Mapping[K2, V2]) -> frozendict[Union[K, K2], Union[V, V2]]: ...
68 @overload
69 def set(self: SelfT, key: K, value: V) -> SelfT: ...
70 @overload
71 def set(self: SelfT, key: K2, value: V) -> frozendict[Union[K, K2], V]: ...
72 @overload
73 def set(self: SelfT, key: K, value: V2) -> frozendict[K, Union[V, V2]]: ...
74 @overload
75 def set(self: SelfT, key: K2, value: V2) -> frozendict[Union[K, K2], Union[V, V2]]: ...
76 @overload
77 def setdefault(self: SelfT, key: K) -> SelfT: ...
78 @overload
79 def setdefault(self: SelfT, key: K2) -> SelfT: ...
80 @overload
81 def setdefault(self: SelfT, key: K, default: V) -> SelfT: ...
82 @overload
83 def setdefault(self: SelfT, key: K2, default: V) -> frozendict[Union[K, K2], V]: ...
84 @overload
85 def setdefault(self: SelfT, key: K, default: V2) -> frozendict[K, Union[V, V2]]: ...
86 @overload
87 def setdefault(self: SelfT, key: K2, default: V2) -> frozendict[Union[K, K2], Union[V, V2]]: ...
88
89 @classmethod
90 def fromkeys(
91 cls: Type[SelfT],
92 seq: Iterable[K],
93 value: Optional[V] = None
94 ) -> SelfT: ...
95
96
97 FrozenOrderedDict = frozendict
98 c_ext: bool
99
100 class FreezeError(Exception): pass
101
102
103 class FreezeWarning(UserWarning): pass
104
105 # PyCharm complains about returning Hashable, because
106 # it's not subscriptable
107 def deepfreeze(
108 o: Any,
109 custom_converters: Optional[Dict[Any, Callable[[Any], Hashable]]] = None,
110 custom_inverse_converters: Optional[Dict[Any, Callable[[Any], Any]]] = None
111 ) -> Any: ...
112
113 def register(
114 to_convert: Any,
115 converter: Callable[[Any], Any],
116 *,
117 inverse: bool = False
118 ) -> None: ...
119
120 def unregister(
121 type: Any,
122 inverse: bool = False
123 ) -> None: ...