Specialize plain slice type hints (#13007)

This commit is contained in:
Randolf Scholz
2026-01-23 10:35:39 +01:00
committed by GitHub
parent 2ff920f291
commit 5c49b1fe49
15 changed files with 69 additions and 69 deletions
+6 -6
View File
@@ -2,7 +2,7 @@ import os
import sys
from _typeshed import ReadableBuffer, Unused
from collections.abc import Iterator
from typing import Final, Literal, NoReturn, overload
from typing import Final, Literal, NoReturn, SupportsIndex, overload
from typing_extensions import Self, disjoint_base
ACCESS_DEFAULT: Final = 0
@@ -77,14 +77,14 @@ class mmap:
def read(self, n: int | None = None, /) -> bytes: ...
def write(self, bytes: ReadableBuffer, /) -> int: ...
@overload
def __getitem__(self, key: int, /) -> int: ...
def __getitem__(self, key: SupportsIndex, /) -> int: ...
@overload
def __getitem__(self, key: slice, /) -> bytes: ...
def __delitem__(self, key: int | slice, /) -> NoReturn: ...
def __getitem__(self, key: slice[SupportsIndex | None], /) -> bytes: ...
def __delitem__(self, key: SupportsIndex | slice[SupportsIndex | None], /) -> NoReturn: ...
@overload
def __setitem__(self, key: int, value: int, /) -> None: ...
def __setitem__(self, key: SupportsIndex, value: int, /) -> None: ...
@overload
def __setitem__(self, key: slice, value: ReadableBuffer, /) -> None: ...
def __setitem__(self, key: slice[SupportsIndex | None], value: ReadableBuffer, /) -> None: ...
# Doesn't actually exist, but the object actually supports "in" because it has __getitem__,
# so we claim that there is also a __contains__ to help type checkers.
def __contains__(self, o: object, /) -> bool: ...