typing.pyi 10 KB

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