sorteddict.pyi 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. Iterator,
  10. Iterable,
  11. ItemsView,
  12. KeysView,
  13. List,
  14. Mapping,
  15. Optional,
  16. Sequence,
  17. Type,
  18. TypeVar,
  19. Tuple,
  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]], Tuple[Callable[[_KT], Any], List[Tuple[_KT, _VT]]],
  90. ]: ...
  91. def __repr__(self) -> str: ...
  92. def _check(self) -> None: ...
  93. def islice(
  94. self, start: Optional[int] = ..., stop: Optional[int] = ..., reverse=bool,
  95. ) -> Iterator[_KT]: ...
  96. def bisect_left(self, value: _KT) -> int: ...
  97. def bisect_right(self, value: _KT) -> int: ...
  98. class SortedKeysView(KeysView[_KT_co], Sequence[_KT_co]):
  99. @overload
  100. def __getitem__(self, index: int) -> _KT_co: ...
  101. @overload
  102. def __getitem__(self, index: slice) -> List[_KT_co]: ...
  103. def __delitem__(self, index: Union[int, slice]) -> None: ...
  104. class SortedItemsView( # type: ignore
  105. ItemsView[_KT_co, _VT_co], Sequence[Tuple[_KT_co, _VT_co]]
  106. ):
  107. def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ...
  108. @overload
  109. def __getitem__(self, index: int) -> Tuple[_KT_co, _VT_co]: ...
  110. @overload
  111. def __getitem__(self, index: slice) -> List[Tuple[_KT_co, _VT_co]]: ...
  112. def __delitem__(self, index: Union[int, slice]) -> None: ...
  113. class SortedValuesView(ValuesView[_VT_co], Sequence[_VT_co]):
  114. @overload
  115. def __getitem__(self, index: int) -> _VT_co: ...
  116. @overload
  117. def __getitem__(self, index: slice) -> List[_VT_co]: ...
  118. def __delitem__(self, index: Union[int, slice]) -> None: ...