sorteddict.pyi 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. # stub for SortedDict. This is a lightly edited copy of
  2. # https://github.com/grantjenks/python-sortedcontainers/blob/eea42df1f7bad2792e8da77335ff888f04b9e5ae/sortedcontainers/sorteddict.pyi
  3. # (from https://github.com/grantjenks/python-sortedcontainers/pull/107)
  4. from typing import (
  5. Any,
  6. Callable,
  7. Dict,
  8. Hashable,
  9. ItemsView,
  10. Iterable,
  11. Iterator,
  12. KeysView,
  13. List,
  14. Mapping,
  15. Optional,
  16. Sequence,
  17. Tuple,
  18. Type,
  19. TypeVar,
  20. Union,
  21. ValuesView,
  22. overload,
  23. )
  24. _T = TypeVar("_T")
  25. _S = TypeVar("_S")
  26. _T_h = TypeVar("_T_h", bound=Hashable)
  27. _KT = TypeVar("_KT", bound=Hashable) # Key type.
  28. _VT = TypeVar("_VT") # Value type.
  29. _KT_co = TypeVar("_KT_co", covariant=True, bound=Hashable)
  30. _VT_co = TypeVar("_VT_co", covariant=True)
  31. _SD = TypeVar("_SD", bound=SortedDict)
  32. _Key = Callable[[_T], Any]
  33. class SortedDict(Dict[_KT, _VT]):
  34. @overload
  35. def __init__(self, **kwargs: _VT) -> None: ...
  36. @overload
  37. def __init__(self, __map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
  38. @overload
  39. def __init__(
  40. self, __iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT
  41. ) -> None: ...
  42. @overload
  43. def __init__(self, __key: _Key[_KT], **kwargs: _VT) -> None: ...
  44. @overload
  45. def __init__(
  46. self, __key: _Key[_KT], __map: Mapping[_KT, _VT], **kwargs: _VT
  47. ) -> None: ...
  48. @overload
  49. def __init__(
  50. self, __key: _Key[_KT], __iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT
  51. ) -> None: ...
  52. @property
  53. def key(self) -> Optional[_Key[_KT]]: ...
  54. @property
  55. def iloc(self) -> SortedKeysView[_KT]: ...
  56. def clear(self) -> None: ...
  57. def __delitem__(self, key: _KT) -> None: ...
  58. def __iter__(self) -> Iterator[_KT]: ...
  59. def __reversed__(self) -> Iterator[_KT]: ...
  60. def __setitem__(self, key: _KT, value: _VT) -> None: ...
  61. def _setitem(self, key: _KT, value: _VT) -> None: ...
  62. def copy(self: _SD) -> _SD: ...
  63. def __copy__(self: _SD) -> _SD: ...
  64. @classmethod
  65. @overload
  66. def fromkeys(cls, seq: Iterable[_T_h]) -> SortedDict[_T_h, None]: ...
  67. @classmethod
  68. @overload
  69. def fromkeys(cls, seq: Iterable[_T_h], value: _S) -> SortedDict[_T_h, _S]: ...
  70. def keys(self) -> SortedKeysView[_KT]: ...
  71. def items(self) -> SortedItemsView[_KT, _VT]: ...
  72. def values(self) -> SortedValuesView[_VT]: ...
  73. @overload
  74. def pop(self, key: _KT) -> _VT: ...
  75. @overload
  76. def pop(self, key: _KT, default: _T = ...) -> Union[_VT, _T]: ...
  77. def popitem(self, index: int = ...) -> Tuple[_KT, _VT]: ...
  78. def peekitem(self, index: int = ...) -> Tuple[_KT, _VT]: ...
  79. def setdefault(self, key: _KT, default: Optional[_VT] = ...) -> _VT: ...
  80. @overload
  81. def update(self, __map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
  82. @overload
  83. def update(self, __iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
  84. @overload
  85. def update(self, **kwargs: _VT) -> None: ...
  86. def __reduce__(
  87. self,
  88. ) -> Tuple[
  89. Type[SortedDict[_KT, _VT]],
  90. Tuple[Callable[[_KT], Any], List[Tuple[_KT, _VT]]],
  91. ]: ...
  92. def __repr__(self) -> str: ...
  93. def _check(self) -> None: ...
  94. def islice(
  95. self,
  96. start: Optional[int] = ...,
  97. stop: Optional[int] = ...,
  98. reverse=bool,
  99. ) -> Iterator[_KT]: ...
  100. def bisect_left(self, value: _KT) -> int: ...
  101. def bisect_right(self, value: _KT) -> int: ...
  102. class SortedKeysView(KeysView[_KT_co], Sequence[_KT_co]):
  103. @overload
  104. def __getitem__(self, index: int) -> _KT_co: ...
  105. @overload
  106. def __getitem__(self, index: slice) -> List[_KT_co]: ...
  107. def __delitem__(self, index: Union[int, slice]) -> None: ...
  108. class SortedItemsView( # type: ignore
  109. ItemsView[_KT_co, _VT_co], Sequence[Tuple[_KT_co, _VT_co]]
  110. ):
  111. def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ...
  112. @overload
  113. def __getitem__(self, index: int) -> Tuple[_KT_co, _VT_co]: ...
  114. @overload
  115. def __getitem__(self, index: slice) -> List[Tuple[_KT_co, _VT_co]]: ...
  116. def __delitem__(self, index: Union[int, slice]) -> None: ...
  117. class SortedValuesView(ValuesView[_VT_co], Sequence[_VT_co]):
  118. @overload
  119. def __getitem__(self, index: int) -> _VT_co: ...
  120. @overload
  121. def __getitem__(self, index: slice) -> List[_VT_co]: ...
  122. def __delitem__(self, index: Union[int, slice]) -> None: ...