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 Generic 8from typing import Hashable 9from typing import Iterator 10from typing import Iterable 11from typing import Mapping 12from typing import MutableMapping 13from typing import Optional 14from typing import Sequence 15from typing import AbstractSet 16from typing import Sized 17from typing import Tuple 18from typing import TypeVar 19from typing import Union 20from typing import overload 21 22T = TypeVar('T') 23KT = TypeVar('KT') 24VT = TypeVar('VT') 25 26class PMap(Mapping[KT, VT], Hashable): 27 def __add__(self, other: PMap[KT, VT]) -> PMap[KT, VT]: ... 28 def __getitem__(self, key: KT) -> VT: ... 29 def __hash__(self) -> int: ... 30 def __iter__(self) -> Iterator[KT]: ... 31 def __len__(self) -> int: ... 32 def copy(self) -> PMap[KT, VT]: ... 33 def discard(self, key: KT) -> PMap[KT, VT]: ... 34 def evolver(self) -> 'PMapEvolver[KT, VT]': ... 35 def iteritems(self) -> Iterable[Tuple[KT, VT]]: ... 36 def iterkeys(self) -> Iterable[KT]: ... 37 def itervalues(self) -> Iterable[VT]: ... 38 def remove(self, key: KT) -> PMap[KT, VT]: ... 39 def set(self, key: KT, val: VT) -> PMap[KT, VT]: ... 40 def transform(self, *transformations: Any) -> PMap[KT, VT]: ... 41 def update(self, *args: Mapping): ... 42 def update_with(self, update_fn: Callable[[VT, VT], VT], *args: Mapping) -> Any: ... 43 44 45class PMapEvolver(MutableMapping[KT, VT]): 46 def __delitem__(self, key: KT) -> None: ... 47 def __getitem__(self, key: KT) -> VT: ... 48 def __iter__(self) -> Iterator[KT]: ... 49 def __len__(self) -> int: ... 50 def __setitem__(self, key: KT, val: VT) -> None: ... 51 def is_dirty(self) -> bool: ... 52 def persistent(self) -> PMap[KT, VT]: ... 53 def remove(self, key: KT) -> PMapEvolver[KT, VT]: ... 54 def set(self, key: KT, val: VT) -> PMapEvolver[KT, VT]: ... 55 56 57class PVector(Sequence[T], Hashable): 58 def __add__(self, other: PVector[T]) -> PVector[T]: ... 59 @overload 60 def __getitem__(self, index: int) -> T: ... 61 @overload 62 def __getitem__(self, index: slice) -> PVector[T]: ... 63 def __hash__(self) -> int: ... 64 def __len__(self) -> int: ... 65 def __mul__(self, other: PVector[T]) -> PVector[T]: ... 66 def append(self, val: T) -> PVector[T]: ... 67 def delete(self, index: int, stop: Optional[int]) -> PVector[T]: ... 68 def evolver(self) -> 'PVectorEvolver[T]': ... 69 def extend(self, obj: Iterable[T]) -> PVector[T]: ... 70 def mset(self, *args: Iterable[Union[T, int]]) -> PVector[T]: ... 71 def remove(self, value: T) -> PVector[T]: ... 72 # Not compatible with MutableSequence 73 def set(self, i: int, val: T) -> PVector[T]: ... 74 def transform(self, *transformations: Any) -> PVector[T]: ... 75 76 77class PVectorEvolver(Sequence[T], Sized): 78 def __delitem__(self, i: Union[int, slice]) -> None: ... 79 @overload 80 def __getitem__(self, index: int) -> T: ... 81 # Not actually supported 82 @overload 83 def __getitem__(self, index: slice) -> PVectorEvolver[T]: ... 84 def __len__(self) -> int: ... 85 def __setitem__(self, index: int, val: T) -> None: ... 86 def append(self, val: T) -> PVectorEvolver[T]: ... 87 def delete(self, value: T) -> PVectorEvolver[T]: ... 88 def extend(self, obj: Iterable[T]) -> PVectorEvolver[T]: ... 89 def is_dirty(self) -> bool: ... 90 def persistent(self) -> PVector[T]: ... 91 def set(self, i: int, val: T) -> PVectorEvolver[T]: ... 92 93 94class PSet(AbstractSet[T], Hashable): 95 def __contains__(self, element: object) -> bool: ... 96 def __hash__(self) -> int: ... 97 def __iter__(self) -> Iterator[KT]: ... 98 def __len__(self) -> int: ... 99 def add(self, element: T) -> PSet[T]: ... 100 def copy(self) -> PSet[T]: ... 101 def difference(self, iterable: Iterable) -> PSet[T]: ... 102 def discard(self, element: T) -> PSet[T]: ... 103 def evolver(self) -> 'PSetEvolver[T]': ... 104 def intersection(self, iterable: Iterable) -> PSet[T]: ... 105 def issubset(self, iterable: Iterable) -> bool: ... 106 def issuperset(self, iterable: Iterable) -> bool: ... 107 def remove(self, element: T) -> PSet[T]: ... 108 def symmetric_difference(self, iterable: Iterable[T]) -> PSet[T]: ... 109 def union(self, iterable: Iterable[T]) -> PSet[T]: ... 110 def update(self, iterable: Iterable[T]) -> PSet[T]: ... 111 112 113class PSetEvolver(Generic[T], Sized): 114 def __len__(self) -> int: ... 115 def add(self, element: T) -> PSetEvolver[T]: ... 116 def is_dirty(self) -> bool: ... 117 def persistent(self) -> PSet[T]: ... 118 def remove(self, element: T) -> PSetEvolver[T]: ... 119 120 121class PBag(Generic[T], Sized, Hashable): 122 def __add__(self, other: PBag[T]) -> PBag[T]: ... 123 def __and__(self, other: PBag[T]) -> PBag[T]: ... 124 def __contains__(self, elem: object) -> bool: ... 125 def __hash__(self) -> int: ... 126 def __iter__(self) -> Iterator[T]: ... 127 def __len__(self) -> int: ... 128 def __or__(self, other: PBag[T]) -> PBag[T]: ... 129 def __sub__(self, other: PBag[T]) -> PBag[T]: ... 130 def add(self, elem: T) -> PBag[T]: ... 131 def count(self, elem: T) -> int: ... 132 def remove(self, elem: T) -> PBag[T]: ... 133 def update(self, iterable: Iterable[T]) -> PBag[T]: ... 134 135 136class PDeque(Sequence[T], Hashable): 137 @overload 138 def __getitem__(self, index: int) -> T: ... 139 @overload 140 def __getitem__(self, index: slice) -> PDeque[T]: ... 141 def __hash__(self) -> int: ... 142 def __len__(self) -> int: ... 143 def __lt__(self, other: PDeque[T]) -> bool: ... 144 def append(self, elem: T) -> PDeque[T]: ... 145 def appendleft(self, elem: T) -> PDeque[T]: ... 146 def extend(self, iterable: Iterable[T]) -> PDeque[T]: ... 147 def extendleft(self, iterable: Iterable[T]) -> PDeque[T]: ... 148 @property 149 def left(self) -> T: ... 150 # The real return type is Integral according to what pyrsistent 151 # checks at runtime but mypy doesn't deal in numeric.*: 152 # https://github.com/python/mypy/issues/2636 153 @property 154 def maxlen(self) -> int: ... 155 def pop(self, count: int = 1) -> PDeque[T]: ... 156 def popleft(self, count: int = 1) -> PDeque[T]: ... 157 def remove(self, elem: T) -> PDeque[T]: ... 158 def reverse(self) -> PDeque[T]: ... 159 @property 160 def right(self) -> T: ... 161 def rotate(self, steps: int) -> PDeque[T]: ... 162 163 164class PList(Sequence[T], Hashable): 165 @overload 166 def __getitem__(self, index: int) -> T: ... 167 @overload 168 def __getitem__(self, index: slice) -> PList[T]: ... 169 def __hash__(self) -> int: ... 170 def __len__(self) -> int: ... 171 def __lt__(self, other: PDeque[T]) -> bool: ... 172 def cons(self, elem: T) -> PList[T]: ... 173 def mcons(self, iterable: Iterable[T]) -> PList[T]: ... 174 def remove(self, elem: T) -> PList[T]: ... 175 def reverse(self) -> PList[T]: ... 176 def split(self, index: int) -> Tuple[PList[T], PList[T]]: ... 177 178 179class CheckedPMap(PMap[KT, VT]): 180 pass 181 182 183class CheckedPVector(PVector[T]): 184 pass 185 186 187class CheckedPSet(PSet[T]): 188 pass 189