Type hint support for slices and __index__ in SequenceProxy

This commit is contained in:
Jakub Kuczys 2022-10-03 13:27:38 +02:00 committed by GitHub
parent c6decedf7b
commit d2c6a32543
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -46,6 +46,7 @@ from typing import (
Protocol, Protocol,
Set, Set,
Sequence, Sequence,
SupportsIndex,
Tuple, Tuple,
Type, Type,
TypeVar, TypeVar,
@ -227,7 +228,15 @@ class SequenceProxy(Sequence[T_co]):
def __repr__(self) -> str: def __repr__(self) -> str:
return f"SequenceProxy({self.__proxied!r})" return f"SequenceProxy({self.__proxied!r})"
def __getitem__(self, idx: int) -> T_co: @overload
def __getitem__(self, idx: SupportsIndex) -> T_co:
...
@overload
def __getitem__(self, idx: slice) -> List[T_co]:
...
def __getitem__(self, idx: Union[SupportsIndex, slice]) -> Union[T_co, List[T_co]]:
return self.__copied[idx] return self.__copied[idx]
def __len__(self) -> int: def __len__(self) -> int: