2020-04-22 12:45:40 +00:00
|
|
|
# stub for SortedDict. This is a lightly edited copy of
|
|
|
|
# https://github.com/grantjenks/python-sortedcontainers/blob/eea42df1f7bad2792e8da77335ff888f04b9e5ae/sortedcontainers/sorteddict.pyi
|
|
|
|
# (from https://github.com/grantjenks/python-sortedcontainers/pull/107)
|
|
|
|
|
2022-12-21 18:05:21 +00:00
|
|
|
from __future__ import annotations
|
|
|
|
|
2020-04-22 12:45:40 +00:00
|
|
|
from typing import (
|
|
|
|
Any,
|
|
|
|
Callable,
|
|
|
|
Dict,
|
|
|
|
Hashable,
|
|
|
|
ItemsView,
|
2021-01-08 14:08:44 +00:00
|
|
|
Iterable,
|
|
|
|
Iterator,
|
2020-04-22 12:45:40 +00:00
|
|
|
KeysView,
|
|
|
|
List,
|
|
|
|
Mapping,
|
|
|
|
Optional,
|
|
|
|
Sequence,
|
2021-01-08 14:08:44 +00:00
|
|
|
Tuple,
|
2020-04-22 12:45:40 +00:00
|
|
|
Type,
|
|
|
|
TypeVar,
|
|
|
|
Union,
|
|
|
|
ValuesView,
|
|
|
|
overload,
|
|
|
|
)
|
|
|
|
|
|
|
|
_T = TypeVar("_T")
|
|
|
|
_S = TypeVar("_S")
|
|
|
|
_T_h = TypeVar("_T_h", bound=Hashable)
|
|
|
|
_KT = TypeVar("_KT", bound=Hashable) # Key type.
|
|
|
|
_VT = TypeVar("_VT") # Value type.
|
|
|
|
_KT_co = TypeVar("_KT_co", covariant=True, bound=Hashable)
|
|
|
|
_VT_co = TypeVar("_VT_co", covariant=True)
|
|
|
|
_SD = TypeVar("_SD", bound=SortedDict)
|
|
|
|
_Key = Callable[[_T], Any]
|
|
|
|
|
|
|
|
class SortedDict(Dict[_KT, _VT]):
|
|
|
|
@overload
|
|
|
|
def __init__(self, **kwargs: _VT) -> None: ...
|
|
|
|
@overload
|
|
|
|
def __init__(self, __map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
|
|
|
|
@overload
|
|
|
|
def __init__(
|
|
|
|
self, __iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT
|
|
|
|
) -> None: ...
|
|
|
|
@overload
|
|
|
|
def __init__(self, __key: _Key[_KT], **kwargs: _VT) -> None: ...
|
|
|
|
@overload
|
|
|
|
def __init__(
|
|
|
|
self, __key: _Key[_KT], __map: Mapping[_KT, _VT], **kwargs: _VT
|
|
|
|
) -> None: ...
|
|
|
|
@overload
|
|
|
|
def __init__(
|
|
|
|
self, __key: _Key[_KT], __iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT
|
|
|
|
) -> None: ...
|
|
|
|
@property
|
|
|
|
def key(self) -> Optional[_Key[_KT]]: ...
|
|
|
|
@property
|
|
|
|
def iloc(self) -> SortedKeysView[_KT]: ...
|
|
|
|
def clear(self) -> None: ...
|
|
|
|
def __delitem__(self, key: _KT) -> None: ...
|
|
|
|
def __iter__(self) -> Iterator[_KT]: ...
|
|
|
|
def __reversed__(self) -> Iterator[_KT]: ...
|
|
|
|
def __setitem__(self, key: _KT, value: _VT) -> None: ...
|
|
|
|
def _setitem(self, key: _KT, value: _VT) -> None: ...
|
|
|
|
def copy(self: _SD) -> _SD: ...
|
|
|
|
def __copy__(self: _SD) -> _SD: ...
|
|
|
|
@classmethod
|
|
|
|
@overload
|
2022-02-18 15:57:26 +00:00
|
|
|
def fromkeys(
|
|
|
|
cls, seq: Iterable[_T_h], value: None = ...
|
|
|
|
) -> SortedDict[_T_h, None]: ...
|
2020-04-22 12:45:40 +00:00
|
|
|
@classmethod
|
|
|
|
@overload
|
|
|
|
def fromkeys(cls, seq: Iterable[_T_h], value: _S) -> SortedDict[_T_h, _S]: ...
|
2022-02-18 15:57:26 +00:00
|
|
|
# As of Python 3.10, `dict_{keys,items,values}` have an extra `mapping` attribute and so
|
|
|
|
# `Sorted{Keys,Items,Values}View` are no longer compatible with them.
|
|
|
|
# See https://github.com/python/typeshed/issues/6837
|
|
|
|
def keys(self) -> SortedKeysView[_KT]: ... # type: ignore[override]
|
|
|
|
def items(self) -> SortedItemsView[_KT, _VT]: ... # type: ignore[override]
|
|
|
|
def values(self) -> SortedValuesView[_VT]: ... # type: ignore[override]
|
2020-04-22 12:45:40 +00:00
|
|
|
@overload
|
|
|
|
def pop(self, key: _KT) -> _VT: ...
|
|
|
|
@overload
|
|
|
|
def pop(self, key: _KT, default: _T = ...) -> Union[_VT, _T]: ...
|
|
|
|
def popitem(self, index: int = ...) -> Tuple[_KT, _VT]: ...
|
|
|
|
def peekitem(self, index: int = ...) -> Tuple[_KT, _VT]: ...
|
|
|
|
def setdefault(self, key: _KT, default: Optional[_VT] = ...) -> _VT: ...
|
2022-05-06 12:35:20 +00:00
|
|
|
# Mypy now reports the first overload as an error, because typeshed widened the type
|
|
|
|
# of `__map` to its internal `_typeshed.SupportsKeysAndGetItem` type in
|
|
|
|
# https://github.com/python/typeshed/pull/6653
|
|
|
|
# Since sorteddicts don't change the signature of `update` from that of `dict`, we
|
|
|
|
# let the stubs for `update` inherit from the stubs for `dict`. (I suspect we could
|
|
|
|
# do the same for many othe methods.) We leave the stubs commented to better track
|
|
|
|
# how this file has evolved from the original stubs.
|
|
|
|
# @overload
|
|
|
|
# def update(self, __map: Mapping[_KT, _VT], **kwargs: _VT) -> None: ...
|
|
|
|
# @overload
|
|
|
|
# def update(self, __iterable: Iterable[Tuple[_KT, _VT]], **kwargs: _VT) -> None: ...
|
|
|
|
# @overload
|
|
|
|
# def update(self, **kwargs: _VT) -> None: ...
|
2020-04-22 12:45:40 +00:00
|
|
|
def __reduce__(
|
|
|
|
self,
|
|
|
|
) -> Tuple[
|
|
|
|
Type[SortedDict[_KT, _VT]],
|
|
|
|
Tuple[Callable[[_KT], Any], List[Tuple[_KT, _VT]]],
|
|
|
|
]: ...
|
|
|
|
def __repr__(self) -> str: ...
|
|
|
|
def _check(self) -> None: ...
|
|
|
|
def islice(
|
|
|
|
self,
|
|
|
|
start: Optional[int] = ...,
|
|
|
|
stop: Optional[int] = ...,
|
2022-04-25 12:32:35 +00:00
|
|
|
reverse: bool = ...,
|
2020-04-22 12:45:40 +00:00
|
|
|
) -> Iterator[_KT]: ...
|
|
|
|
def bisect_left(self, value: _KT) -> int: ...
|
|
|
|
def bisect_right(self, value: _KT) -> int: ...
|
|
|
|
|
|
|
|
class SortedKeysView(KeysView[_KT_co], Sequence[_KT_co]):
|
|
|
|
@overload
|
|
|
|
def __getitem__(self, index: int) -> _KT_co: ...
|
|
|
|
@overload
|
|
|
|
def __getitem__(self, index: slice) -> List[_KT_co]: ...
|
|
|
|
def __delitem__(self, index: Union[int, slice]) -> None: ...
|
|
|
|
|
2022-04-27 13:03:44 +00:00
|
|
|
class SortedItemsView(ItemsView[_KT_co, _VT_co], Sequence[Tuple[_KT_co, _VT_co]]):
|
2020-04-22 12:45:40 +00:00
|
|
|
def __iter__(self) -> Iterator[Tuple[_KT_co, _VT_co]]: ...
|
|
|
|
@overload
|
|
|
|
def __getitem__(self, index: int) -> Tuple[_KT_co, _VT_co]: ...
|
|
|
|
@overload
|
|
|
|
def __getitem__(self, index: slice) -> List[Tuple[_KT_co, _VT_co]]: ...
|
|
|
|
def __delitem__(self, index: Union[int, slice]) -> None: ...
|
|
|
|
|
|
|
|
class SortedValuesView(ValuesView[_VT_co], Sequence[_VT_co]):
|
|
|
|
@overload
|
|
|
|
def __getitem__(self, index: int) -> _VT_co: ...
|
|
|
|
@overload
|
|
|
|
def __getitem__(self, index: slice) -> List[_VT_co]: ...
|
|
|
|
def __delitem__(self, index: Union[int, slice]) -> None: ...
|