structures.pyi 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. from collections.abc import Callable
  2. from collections.abc import Iterable
  3. from collections.abc import Iterator
  4. from collections.abc import Mapping
  5. from typing import Any
  6. from typing import Generic
  7. from typing import Literal
  8. from typing import NoReturn
  9. from typing import overload
  10. from typing import TypeVar
  11. from .mixins import (
  12. ImmutableDictMixin,
  13. ImmutableListMixin,
  14. ImmutableMultiDictMixin,
  15. UpdateDictMixin,
  16. )
  17. D = TypeVar("D")
  18. K = TypeVar("K")
  19. T = TypeVar("T")
  20. V = TypeVar("V")
  21. _CD = TypeVar("_CD", bound="CallbackDict")
  22. def is_immutable(self: object) -> NoReturn: ...
  23. def iter_multi_items(
  24. mapping: Mapping[K, V | Iterable[V]] | Iterable[tuple[K, V]]
  25. ) -> Iterator[tuple[K, V]]: ...
  26. class ImmutableList(ImmutableListMixin[V]): ...
  27. class TypeConversionDict(dict[K, V]):
  28. @overload
  29. def get(self, key: K, default: None = ..., type: None = ...) -> V | None: ...
  30. @overload
  31. def get(self, key: K, default: D, type: None = ...) -> D | V: ...
  32. @overload
  33. def get(self, key: K, default: D, type: Callable[[V], T]) -> D | T: ...
  34. @overload
  35. def get(self, key: K, type: Callable[[V], T]) -> T | None: ...
  36. class ImmutableTypeConversionDict(ImmutableDictMixin[K, V], TypeConversionDict[K, V]):
  37. def copy(self) -> TypeConversionDict[K, V]: ...
  38. def __copy__(self) -> ImmutableTypeConversionDict: ...
  39. class MultiDict(TypeConversionDict[K, V]):
  40. def __init__(
  41. self,
  42. mapping: Mapping[K, Iterable[V] | V] | Iterable[tuple[K, V]] | None = None,
  43. ) -> None: ...
  44. def __getitem__(self, item: K) -> V: ...
  45. def __setitem__(self, key: K, value: V) -> None: ...
  46. def add(self, key: K, value: V) -> None: ...
  47. @overload
  48. def getlist(self, key: K) -> list[V]: ...
  49. @overload
  50. def getlist(self, key: K, type: Callable[[V], T] = ...) -> list[T]: ...
  51. def setlist(self, key: K, new_list: Iterable[V]) -> None: ...
  52. def setdefault(self, key: K, default: V | None = None) -> V: ...
  53. def setlistdefault(
  54. self, key: K, default_list: Iterable[V] | None = None
  55. ) -> list[V]: ...
  56. def items(self, multi: bool = False) -> Iterator[tuple[K, V]]: ... # type: ignore
  57. def lists(self) -> Iterator[tuple[K, list[V]]]: ...
  58. def values(self) -> Iterator[V]: ... # type: ignore
  59. def listvalues(self) -> Iterator[list[V]]: ...
  60. def copy(self) -> MultiDict[K, V]: ...
  61. def deepcopy(self, memo: Any = None) -> MultiDict[K, V]: ...
  62. @overload
  63. def to_dict(self) -> dict[K, V]: ...
  64. @overload
  65. def to_dict(self, flat: Literal[False]) -> dict[K, list[V]]: ...
  66. def update( # type: ignore
  67. self, mapping: Mapping[K, Iterable[V] | V] | Iterable[tuple[K, V]]
  68. ) -> None: ...
  69. @overload
  70. def pop(self, key: K) -> V: ...
  71. @overload
  72. def pop(self, key: K, default: V | T = ...) -> V | T: ...
  73. def popitem(self) -> tuple[K, V]: ...
  74. def poplist(self, key: K) -> list[V]: ...
  75. def popitemlist(self) -> tuple[K, list[V]]: ...
  76. def __copy__(self) -> MultiDict[K, V]: ...
  77. def __deepcopy__(self, memo: Any) -> MultiDict[K, V]: ...
  78. class _omd_bucket(Generic[K, V]):
  79. prev: _omd_bucket | None
  80. next: _omd_bucket | None
  81. key: K
  82. value: V
  83. def __init__(self, omd: OrderedMultiDict, key: K, value: V) -> None: ...
  84. def unlink(self, omd: OrderedMultiDict) -> None: ...
  85. class OrderedMultiDict(MultiDict[K, V]):
  86. _first_bucket: _omd_bucket | None
  87. _last_bucket: _omd_bucket | None
  88. def __init__(self, mapping: Mapping[K, V] | None = None) -> None: ...
  89. def __eq__(self, other: object) -> bool: ...
  90. def __getitem__(self, key: K) -> V: ...
  91. def __setitem__(self, key: K, value: V) -> None: ...
  92. def __delitem__(self, key: K) -> None: ...
  93. def keys(self) -> Iterator[K]: ... # type: ignore
  94. def __iter__(self) -> Iterator[K]: ...
  95. def values(self) -> Iterator[V]: ... # type: ignore
  96. def items(self, multi: bool = False) -> Iterator[tuple[K, V]]: ... # type: ignore
  97. def lists(self) -> Iterator[tuple[K, list[V]]]: ...
  98. def listvalues(self) -> Iterator[list[V]]: ...
  99. def add(self, key: K, value: V) -> None: ...
  100. @overload
  101. def getlist(self, key: K) -> list[V]: ...
  102. @overload
  103. def getlist(self, key: K, type: Callable[[V], T] = ...) -> list[T]: ...
  104. def setlist(self, key: K, new_list: Iterable[V]) -> None: ...
  105. def setlistdefault(
  106. self, key: K, default_list: Iterable[V] | None = None
  107. ) -> list[V]: ...
  108. def update( # type: ignore
  109. self, mapping: Mapping[K, V] | Iterable[tuple[K, V]]
  110. ) -> None: ...
  111. def poplist(self, key: K) -> list[V]: ...
  112. @overload
  113. def pop(self, key: K) -> V: ...
  114. @overload
  115. def pop(self, key: K, default: V | T = ...) -> V | T: ...
  116. def popitem(self) -> tuple[K, V]: ...
  117. def popitemlist(self) -> tuple[K, list[V]]: ...
  118. class CombinedMultiDict(ImmutableMultiDictMixin[K, V], MultiDict[K, V]): # type: ignore
  119. dicts: list[MultiDict[K, V]]
  120. def __init__(self, dicts: Iterable[MultiDict[K, V]] | None) -> None: ...
  121. @classmethod
  122. def fromkeys(cls, keys: Any, value: Any = None) -> NoReturn: ...
  123. def __getitem__(self, key: K) -> V: ...
  124. @overload # type: ignore
  125. def get(self, key: K) -> V | None: ...
  126. @overload
  127. def get(self, key: K, default: V | T = ...) -> V | T: ...
  128. @overload
  129. def get(
  130. self, key: K, default: T | None = None, type: Callable[[V], T] = ...
  131. ) -> T | None: ...
  132. @overload
  133. def getlist(self, key: K) -> list[V]: ...
  134. @overload
  135. def getlist(self, key: K, type: Callable[[V], T] = ...) -> list[T]: ...
  136. def _keys_impl(self) -> set[K]: ...
  137. def keys(self) -> set[K]: ... # type: ignore
  138. def __iter__(self) -> set[K]: ... # type: ignore
  139. def items(self, multi: bool = False) -> Iterator[tuple[K, V]]: ... # type: ignore
  140. def values(self) -> Iterator[V]: ... # type: ignore
  141. def lists(self) -> Iterator[tuple[K, list[V]]]: ...
  142. def listvalues(self) -> Iterator[list[V]]: ...
  143. def copy(self) -> MultiDict[K, V]: ...
  144. @overload
  145. def to_dict(self) -> dict[K, V]: ...
  146. @overload
  147. def to_dict(self, flat: Literal[False]) -> dict[K, list[V]]: ...
  148. def __contains__(self, key: K) -> bool: ... # type: ignore
  149. def has_key(self, key: K) -> bool: ...
  150. class ImmutableDict(ImmutableDictMixin[K, V], dict[K, V]):
  151. def copy(self) -> dict[K, V]: ...
  152. def __copy__(self) -> ImmutableDict[K, V]: ...
  153. class ImmutableMultiDict( # type: ignore
  154. ImmutableMultiDictMixin[K, V], MultiDict[K, V]
  155. ):
  156. def copy(self) -> MultiDict[K, V]: ...
  157. def __copy__(self) -> ImmutableMultiDict[K, V]: ...
  158. class ImmutableOrderedMultiDict( # type: ignore
  159. ImmutableMultiDictMixin[K, V], OrderedMultiDict[K, V]
  160. ):
  161. def _iter_hashitems(self) -> Iterator[tuple[int, tuple[K, V]]]: ...
  162. def copy(self) -> OrderedMultiDict[K, V]: ...
  163. def __copy__(self) -> ImmutableOrderedMultiDict[K, V]: ...
  164. class CallbackDict(UpdateDictMixin[K, V], dict[K, V]):
  165. def __init__(
  166. self,
  167. initial: Mapping[K, V] | Iterable[tuple[K, V]] | None = None,
  168. on_update: Callable[[_CD], None] | None = None,
  169. ) -> None: ...
  170. class HeaderSet(set[str]):
  171. _headers: list[str]
  172. _set: set[str]
  173. on_update: Callable[[HeaderSet], None] | None
  174. def __init__(
  175. self,
  176. headers: Iterable[str] | None = None,
  177. on_update: Callable[[HeaderSet], None] | None = None,
  178. ) -> None: ...
  179. def add(self, header: str) -> None: ...
  180. def remove(self, header: str) -> None: ...
  181. def update(self, iterable: Iterable[str]) -> None: ... # type: ignore
  182. def discard(self, header: str) -> None: ...
  183. def find(self, header: str) -> int: ...
  184. def index(self, header: str) -> int: ...
  185. def clear(self) -> None: ...
  186. def as_set(self, preserve_casing: bool = False) -> set[str]: ...
  187. def to_header(self) -> str: ...
  188. def __getitem__(self, idx: int) -> str: ...
  189. def __delitem__(self, idx: int) -> None: ...
  190. def __setitem__(self, idx: int, value: str) -> None: ...
  191. def __contains__(self, header: str) -> bool: ... # type: ignore
  192. def __len__(self) -> int: ...
  193. def __iter__(self) -> Iterator[str]: ...