__init__.pyi 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  1. import abc
  2. from typing import (
  3. Generic,
  4. Iterable,
  5. Iterator,
  6. Mapping,
  7. MutableMapping,
  8. TypeVar,
  9. overload,
  10. )
  11. class istr(str): ...
  12. upstr = istr
  13. _S = str | istr
  14. _T = TypeVar("_T")
  15. _T_co = TypeVar("_T_co", covariant=True)
  16. _D = TypeVar("_D")
  17. class MultiMapping(Mapping[_S, _T_co]):
  18. @overload
  19. @abc.abstractmethod
  20. def getall(self, key: _S) -> list[_T_co]: ...
  21. @overload
  22. @abc.abstractmethod
  23. def getall(self, key: _S, default: _D) -> list[_T_co] | _D: ...
  24. @overload
  25. @abc.abstractmethod
  26. def getone(self, key: _S) -> _T_co: ...
  27. @overload
  28. @abc.abstractmethod
  29. def getone(self, key: _S, default: _D) -> _T_co | _D: ...
  30. _Arg = (
  31. Mapping[str, _T]
  32. | Mapping[istr, _T]
  33. | dict[str, _T]
  34. | dict[istr, _T]
  35. | MultiMapping[_T]
  36. | Iterable[tuple[str, _T]]
  37. | Iterable[tuple[istr, _T]]
  38. )
  39. class MutableMultiMapping(MultiMapping[_T], MutableMapping[_S, _T], Generic[_T]):
  40. @abc.abstractmethod
  41. def add(self, key: _S, value: _T) -> None: ...
  42. @abc.abstractmethod
  43. def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
  44. @overload
  45. @abc.abstractmethod
  46. def popone(self, key: _S) -> _T: ...
  47. @overload
  48. @abc.abstractmethod
  49. def popone(self, key: _S, default: _D) -> _T | _D: ...
  50. @overload
  51. @abc.abstractmethod
  52. def popall(self, key: _S) -> list[_T]: ...
  53. @overload
  54. @abc.abstractmethod
  55. def popall(self, key: _S, default: _D) -> list[_T] | _D: ...
  56. class MultiDict(MutableMultiMapping[_T], Generic[_T]):
  57. def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
  58. def copy(self) -> MultiDict[_T]: ...
  59. def __getitem__(self, k: _S) -> _T: ...
  60. def __setitem__(self, k: _S, v: _T) -> None: ...
  61. def __delitem__(self, v: _S) -> None: ...
  62. def __iter__(self) -> Iterator[_S]: ...
  63. def __len__(self) -> int: ...
  64. @overload
  65. def getall(self, key: _S) -> list[_T]: ...
  66. @overload
  67. def getall(self, key: _S, default: _D) -> list[_T] | _D: ...
  68. @overload
  69. def getone(self, key: _S) -> _T: ...
  70. @overload
  71. def getone(self, key: _S, default: _D) -> _T | _D: ...
  72. def add(self, key: _S, value: _T) -> None: ...
  73. def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
  74. @overload
  75. def popone(self, key: _S) -> _T: ...
  76. @overload
  77. def popone(self, key: _S, default: _D) -> _T | _D: ...
  78. @overload
  79. def popall(self, key: _S) -> list[_T]: ...
  80. @overload
  81. def popall(self, key: _S, default: _D) -> list[_T] | _D: ...
  82. class CIMultiDict(MutableMultiMapping[_T], Generic[_T]):
  83. def __init__(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
  84. def copy(self) -> CIMultiDict[_T]: ...
  85. def __getitem__(self, k: _S) -> _T: ...
  86. def __setitem__(self, k: _S, v: _T) -> None: ...
  87. def __delitem__(self, v: _S) -> None: ...
  88. def __iter__(self) -> Iterator[_S]: ...
  89. def __len__(self) -> int: ...
  90. @overload
  91. def getall(self, key: _S) -> list[_T]: ...
  92. @overload
  93. def getall(self, key: _S, default: _D) -> list[_T] | _D: ...
  94. @overload
  95. def getone(self, key: _S) -> _T: ...
  96. @overload
  97. def getone(self, key: _S, default: _D) -> _T | _D: ...
  98. def add(self, key: _S, value: _T) -> None: ...
  99. def extend(self, arg: _Arg[_T] = ..., **kwargs: _T) -> None: ...
  100. @overload
  101. def popone(self, key: _S) -> _T: ...
  102. @overload
  103. def popone(self, key: _S, default: _D) -> _T | _D: ...
  104. @overload
  105. def popall(self, key: _S) -> list[_T]: ...
  106. @overload
  107. def popall(self, key: _S, default: _D) -> list[_T] | _D: ...
  108. class MultiDictProxy(MultiMapping[_T], Generic[_T]):
  109. def __init__(self, arg: MultiMapping[_T] | MutableMultiMapping[_T]) -> None: ...
  110. def copy(self) -> MultiDict[_T]: ...
  111. def __getitem__(self, k: _S) -> _T: ...
  112. def __iter__(self) -> Iterator[_S]: ...
  113. def __len__(self) -> int: ...
  114. @overload
  115. def getall(self, key: _S) -> list[_T]: ...
  116. @overload
  117. def getall(self, key: _S, default: _D) -> list[_T] | _D: ...
  118. @overload
  119. def getone(self, key: _S) -> _T: ...
  120. @overload
  121. def getone(self, key: _S, default: _D) -> _T | _D: ...
  122. class CIMultiDictProxy(MultiMapping[_T], Generic[_T]):
  123. def __init__(self, arg: MultiMapping[_T] | MutableMultiMapping[_T]) -> None: ...
  124. def __getitem__(self, k: _S) -> _T: ...
  125. def __iter__(self) -> Iterator[_S]: ...
  126. def __len__(self) -> int: ...
  127. @overload
  128. def getall(self, key: _S) -> list[_T]: ...
  129. @overload
  130. def getall(self, key: _S, default: _D) -> list[_T] | _D: ...
  131. @overload
  132. def getone(self, key: _S) -> _T: ...
  133. @overload
  134. def getone(self, key: _S, default: _D) -> _T | _D: ...
  135. def copy(self) -> CIMultiDict[_T]: ...
  136. def getversion(
  137. md: MultiDict[_T] | CIMultiDict[_T] | MultiDictProxy[_T] | CIMultiDictProxy[_T],
  138. ) -> int: ...