From fcde1e0cf02a06013f7c812fadcf2c26d4a2eddf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Simon?= Date: Fri, 13 Nov 2026 18:24:27 +0100 Subject: [PATCH] GH-16791: Make Sequence.__getitem__(slice) return Self --- stdlib/typing.pyi | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/stdlib/typing.pyi b/stdlib/typing.pyi index b8b90a0934e5..5c5fad76906d 100644 --- a/stdlib/typing.pyi +++ b/stdlib/typing.pyi @@ -684,9 +684,15 @@ class Sequence(Reversible[_T_co], Collection[_T_co]): @overload @abstractmethod def __getitem__(self, index: int, /) -> _T_co: ... - @overload - @abstractmethod - def __getitem__(self, index: slice[int | None], /) -> Sequence[_T_co]: ... + + if sys.version_info >= (3, 11): + @overload + @abstractmethod + def __getitem__(self, index: slice[int | None], /) -> Self: ... + else: + @overload + @abstractmethod + def __getitem__(self, index: slice[int | None], /) -> Sequence[_T_co]: ... # Mixin methods def index(self, value: Any, start: int = 0, stop: int = ..., /) -> int: ...