1# flake8: noqa: E704
2# from https://gist.github.com/WuTheFWasThat/091a17d4b5cab597dfd5d4c2d96faf09
3# Stubs for pyrsistent (Python 3.6)
4#
5from typing import Any
6from typing import Callable
7from typing import Dict
8from typing import Generic
9from typing import Hashable
10from typing import Iterator
11from typing import Iterable
12from typing import List
13from typing import Mapping
14from typing import Optional
15from typing import Sequence
16from typing import AbstractSet
17from typing import Sized
18from typing import Set
19from typing import Tuple
20from typing import TypeVar
21from typing import Type
22from typing import Union
23from typing import overload
24
25T = TypeVar('T')
26KT = TypeVar('KT')
27VT = TypeVar('VT')
28
29
30class PMap(Mapping[KT, VT], Hashable):
31    def __add__(self, other: PMap[KT, VT]) -> PMap[KT, VT]: ...
32    def __getitem__(self, key: KT) -> VT: ...
33    def __getattr__(self, key: str) -> VT: ...
34    def __hash__(self) -> int: ...
35    def __iter__(self) -> Iterator[KT]: ...
36    def __len__(self) -> int: ...
37    def copy(self) -> PMap[KT, VT]: ...
38    def discard(self, key: KT) -> PMap[KT, VT]: ...
39    def evolver(self) -> PMapEvolver[KT, VT]: ...
40    def iteritems(self) -> Iterable[Tuple[KT, VT]]: ...
41    def iterkeys(self) -> Iterable[KT]: ...
42    def itervalues(self) -> Iterable[VT]: ...
43    def remove(self, key: KT) -> PMap[KT, VT]: ...
44    def set(self, key: KT, val: VT) -> PMap[KT, VT]: ...
45    def transform(self, *transformations: Any) -> PMap[KT, VT]: ...
46    def update(self, *args: Mapping): ...
47    def update_with(self, update_fn: Callable[[VT, VT], VT], *args: Mapping) -> Any: ...
48
49
50class PMapEvolver(Generic[KT, VT]):
51    def __delitem__(self, key: KT) -> None: ...
52    def __getitem__(self, key: KT) -> VT: ...
53    def __len__(self) -> int: ...
54    def __setitem__(self, key: KT, val: VT) -> None: ...
55    def is_dirty(self) -> bool: ...
56    def persistent(self) -> PMap[KT, VT]: ...
57    def remove(self, key: KT) -> PMapEvolver[KT, VT]: ...
58    def set(self, key: KT, val: VT) -> PMapEvolver[KT, VT]: ...
59
60
61class PVector(Sequence[T], Hashable):
62    def __add__(self, other: PVector[T]) -> PVector[T]: ...
63    @overload
64    def __getitem__(self, index: int) -> T: ...
65    @overload
66    def __getitem__(self, index: slice) -> PVector[T]: ...
67    def __hash__(self) -> int: ...
68    def __len__(self) -> int: ...
69    def __mul__(self, other: PVector[T]) -> PVector[T]: ...
70    def append(self, val: T) -> PVector[T]: ...
71    def delete(self, index: int, stop: Optional[int]) -> PVector[T]: ...
72    def evolver(self) -> PVectorEvolver[T]: ...
73    def extend(self, obj: Iterable[T]) -> PVector[T]: ...
74    def tolist(self) -> List[T]: ...
75    def mset(self, *args: Iterable[Union[T, int]]) -> PVector[T]: ...
76    def remove(self, value: T) -> PVector[T]: ...
77    # Not compatible with MutableSequence
78    def set(self, i: int, val: T) -> PVector[T]: ...
79    def transform(self, *transformations: Any) -> PVector[T]: ...
80
81
82class PVectorEvolver(Sequence[T], Sized):
83    def __delitem__(self, i: Union[int, slice]) -> None: ...
84    @overload
85    def __getitem__(self, index: int) -> T: ...
86    # Not actually supported
87    @overload
88    def __getitem__(self, index: slice) -> PVectorEvolver[T]: ...
89    def __len__(self) -> int: ...
90    def __setitem__(self, index: int, val: T) -> None: ...
91    def append(self, val: T) -> PVectorEvolver[T]: ...
92    def delete(self, value: T) -> PVectorEvolver[T]: ...
93    def extend(self, obj: Iterable[T]) -> PVectorEvolver[T]: ...
94    def is_dirty(self) -> bool: ...
95    def persistent(self) -> PVector[T]: ...
96    def set(self, i: int, val: T) -> PVectorEvolver[T]: ...
97
98
99class PSet(AbstractSet[T], Hashable):
100    def __contains__(self, element: object) -> bool: ...
101    def __hash__(self) -> int: ...
102    def __iter__(self) -> Iterator[T]: ...
103    def __len__(self) -> int: ...
104    def add(self, element: T) -> PSet[T]: ...
105    def copy(self) -> PSet[T]: ...
106    def difference(self, iterable: Iterable) -> PSet[T]: ...
107    def discard(self, element: T) -> PSet[T]: ...
108    def evolver(self) -> PSetEvolver[T]: ...
109    def intersection(self, iterable: Iterable) -> PSet[T]: ...
110    def issubset(self, iterable: Iterable) -> bool: ...
111    def issuperset(self, iterable: Iterable) -> bool: ...
112    def remove(self, element: T) -> PSet[T]: ...
113    def symmetric_difference(self, iterable: Iterable[T]) -> PSet[T]: ...
114    def union(self, iterable: Iterable[T]) -> PSet[T]: ...
115    def update(self, iterable: Iterable[T]) -> PSet[T]: ...
116
117
118class PSetEvolver(Generic[T], Sized):
119    def __len__(self) -> int: ...
120    def add(self, element: T) -> PSetEvolver[T]: ...
121    def is_dirty(self) -> bool: ...
122    def persistent(self) -> PSet[T]: ...
123    def remove(self, element: T) -> PSetEvolver[T]: ...
124
125
126class PBag(Generic[T], Sized, Hashable):
127    def __add__(self, other: PBag[T]) -> PBag[T]: ...
128    def __and__(self, other: PBag[T]) -> PBag[T]: ...
129    def __contains__(self, elem: object) -> bool: ...
130    def __hash__(self) -> int: ...
131    def __iter__(self) -> Iterator[T]: ...
132    def __len__(self) -> int: ...
133    def __or__(self, other: PBag[T]) -> PBag[T]: ...
134    def __sub__(self, other: PBag[T]) -> PBag[T]: ...
135    def add(self, elem: T) -> PBag[T]: ...
136    def count(self, elem: T) -> int: ...
137    def remove(self, elem: T) -> PBag[T]: ...
138    def update(self, iterable: Iterable[T]) -> PBag[T]: ...
139
140
141class PDeque(Sequence[T], Hashable):
142    @overload
143    def __getitem__(self, index: int) -> T: ...
144    @overload
145    def __getitem__(self, index: slice) -> PDeque[T]: ...
146    def __hash__(self) -> int: ...
147    def __len__(self) -> int: ...
148    def __lt__(self, other: PDeque[T]) -> bool: ...
149    def append(self, elem: T) -> PDeque[T]: ...
150    def appendleft(self, elem: T) -> PDeque[T]: ...
151    def extend(self, iterable: Iterable[T]) -> PDeque[T]: ...
152    def extendleft(self, iterable: Iterable[T]) -> PDeque[T]: ...
153    @property
154    def left(self) -> T: ...
155    # The real return type is Integral according to what pyrsistent
156    # checks at runtime but mypy doesn't deal in numeric.*:
157    # https://github.com/python/mypy/issues/2636
158    @property
159    def maxlen(self) -> int: ...
160    def pop(self, count: int = 1) -> PDeque[T]: ...
161    def popleft(self, count: int = 1) -> PDeque[T]: ...
162    def remove(self, elem: T) -> PDeque[T]: ...
163    def reverse(self) -> PDeque[T]: ...
164    @property
165    def right(self) -> T: ...
166    def rotate(self, steps: int) -> PDeque[T]: ...
167
168
169class PList(Sequence[T], Hashable):
170    @overload
171    def __getitem__(self, index: int) -> T: ...
172    @overload
173    def __getitem__(self, index: slice) -> PList[T]: ...
174    def __hash__(self) -> int: ...
175    def __len__(self) -> int: ...
176    def __lt__(self, other: PList[T]) -> bool: ...
177    def __gt__(self, other: PList[T]) -> bool: ...
178    def cons(self, elem: T) -> PList[T]: ...
179    @property
180    def first(self) -> T: ...
181    def mcons(self, iterable: Iterable[T]) -> PList[T]: ...
182    def remove(self, elem: T) -> PList[T]: ...
183    @property
184    def rest(self) -> PList[T]: ...
185    def reverse(self) -> PList[T]: ...
186    def split(self, index: int) -> Tuple[PList[T], PList[T]]: ...
187
188T_PClass = TypeVar('T_PClass', bound='PClass')
189
190class PClass(Hashable):
191    def __new__(cls, **kwargs: Any): ...
192    def set(self: T_PClass, *args: Any, **kwargs: Any) -> T_PClass: ...
193    @classmethod
194    def create(
195        cls: Type[T_PClass],
196        kwargs: Any,
197        _factory_fields: Optional[Any] = ...,
198        ignore_extra: bool = ...,
199    ) -> T_PClass: ...
200    def serialize(self, format: Optional[Any] = ...): ...
201    def transform(self, *transformations: Any): ...
202    def __eq__(self, other: object): ...
203    def __ne__(self, other: object): ...
204    def __hash__(self): ...
205    def __reduce__(self): ...
206    def evolver(self) -> PClassEvolver: ...
207    def remove(self: T_PClass, name: Any) -> T_PClass: ...
208
209class PClassEvolver:
210    def __init__(self, original: Any, initial_dict: Any) -> None: ...
211    def __getitem__(self, item: Any): ...
212    def set(self, key: Any, value: Any): ...
213    def __setitem__(self, key: Any, value: Any) -> None: ...
214    def remove(self, item: Any): ...
215    def __delitem__(self, item: Any) -> None: ...
216    def persistent(self) -> PClass: ...
217    def __getattr__(self, item: Any): ...
218
219
220
221class CheckedPMap(PMap[KT, VT]):
222    __key_type__: Type[KT]
223    __value_type__: Type[VT]
224    def __new__(cls, source: Mapping[KT, VT] = ..., size: int = ...) -> CheckedPMap: ...
225    @classmethod
226    def create(cls, source_data: Mapping[KT, VT], _factory_fields: Any = ...) -> CheckedPMap[KT, VT]: ...
227    def serialize(self, format: Optional[Any] = ...) -> Dict[KT, VT]: ...
228
229
230class CheckedPVector(PVector[T]):
231    __type__: Type[T]
232    def __new__(self, initial: Iterable[T] = ...) -> CheckedPVector: ...
233    @classmethod
234    def create(cls, source_data: Iterable[T], _factory_fields: Any = ...) -> CheckedPVector[T]: ...
235    def serialize(self, format: Optional[Any] = ...) -> List[T]: ...
236
237
238class CheckedPSet(PSet[T]):
239    __type__: Type[T]
240    def __new__(cls, initial: Iterable[T] = ...) -> CheckedPSet: ...
241    @classmethod
242    def create(cls, source_data: Iterable[T], _factory_fields: Any = ...) -> CheckedPSet[T]: ...
243    def serialize(self, format: Optional[Any] = ...) -> Set[T]: ...
244
245
246class InvariantException(Exception):
247    invariant_errors: Tuple[Any, ...] = ...  # possibly nested tuple
248    missing_fields: Tuple[str, ...] = ...
249    def __init__(
250        self,
251        error_codes: Any = ...,
252        missing_fields: Any = ...,
253        *args: Any,
254        **kwargs: Any
255    ) -> None: ...
256
257
258class CheckedTypeError(TypeError):
259    source_class: Type[Any]
260    expected_types: Tuple[Any, ...]
261    actual_type: Type[Any]
262    actual_value: Any
263    def __init__(
264        self,
265        source_class: Any,
266        expected_types: Any,
267        actual_type: Any,
268        actual_value: Any,
269        *args: Any,
270        **kwargs: Any
271    ) -> None: ...
272
273
274class CheckedKeyTypeError(CheckedTypeError): ...
275class CheckedValueTypeError(CheckedTypeError): ...
276class CheckedType: ...
277
278
279class PTypeError(TypeError):
280    source_class: Type[Any] = ...
281    field: str = ...
282    expected_types: Tuple[Any, ...] = ...
283    actual_type: Type[Any] = ...
284    def __init__(
285        self,
286        source_class: Any,
287        field: Any,
288        expected_types: Any,
289        actual_type: Any,
290        *args: Any,
291        **kwargs: Any
292    ) -> None: ...
293