Skip to content

toolkit.abc

Classes:

Mapping

Bases: Mapping[_KT, _VT_co]

Methods:

Source code in src/toolkit/abc/_mapping.py
12
13
14
15
16
17
18
19
20
21
22
23
24
25
class Mapping(collections.abc.Mapping[_KT, _VT_co]):
    @overload
    def __getitem__(self, key: _KT) -> _VT_co: ...
    @overload
    def __getitem__(self, key: collections.abc.Iterable[_KT]) -> list[_VT_co]: ...
    def __getitem__(
        self, key: _KT | collections.abc.Iterable[_KT]
    ) -> _VT_co | list[_VT_co]:
        if tp.is_iterable(key):
            return [self._get(k) for k in key]
        return self._get(key)  # pyright: ignore [reportArgumentType]

    @abc.abstractmethod
    def _get(self, key: _KT) -> _VT_co: ...

__getitem__

__getitem__(key: _KT) -> _VT_co
__getitem__(key: Iterable[_KT]) -> list[_VT_co]
__getitem__(key: _KT | Iterable[_KT]) -> _VT_co | list[_VT_co]
Source code in src/toolkit/abc/_mapping.py
17
18
19
20
21
22
def __getitem__(
    self, key: _KT | collections.abc.Iterable[_KT]
) -> _VT_co | list[_VT_co]:
    if tp.is_iterable(key):
        return [self._get(k) for k in key]
    return self._get(key)  # pyright: ignore [reportArgumentType]

Sequence

Bases: Sequence[_T_co]

Methods:

Source code in src/toolkit/abc/_sequence.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
class Sequence(collections.abc.Sequence[_T_co]):
    @overload
    def __getitem__(self, index: int) -> _T_co: ...
    @overload
    def __getitem__(
        self, index: slice | collections.abc.Iterable[int]
    ) -> list[_T_co]: ...
    def __getitem__(
        self, index: int | slice | collections.abc.Iterable[int]
    ) -> _T_co | list[_T_co]:
        if isinstance(index, int):
            return self._get(index)
        if isinstance(index, slice):
            return [self._get(i) for i in range(*index.indices(len(self)))]
        if tp.is_iterable(index):
            return [self._get(i) for i in index]
        return self._get(index)  # pyright: ignore [reportArgumentType]

    @abc.abstractmethod
    def _get(self, idx: int) -> _T_co: ...

__getitem__

__getitem__(index: int) -> _T_co
__getitem__(index: slice | Iterable[int]) -> list[_T_co]
__getitem__(index: int | slice | Iterable[int]) -> _T_co | list[_T_co]
Source code in src/toolkit/abc/_sequence.py
17
18
19
20
21
22
23
24
25
26
def __getitem__(
    self, index: int | slice | collections.abc.Iterable[int]
) -> _T_co | list[_T_co]:
    if isinstance(index, int):
        return self._get(index)
    if isinstance(index, slice):
        return [self._get(i) for i in range(*index.indices(len(self)))]
    if tp.is_iterable(index):
        return [self._get(i) for i in index]
    return self._get(index)  # pyright: ignore [reportArgumentType]