From f99a87a825faec801c7a37606f85e2352832bb0d Mon Sep 17 00:00:00 2001 From: Sebastian Rittau Date: Thu, 20 Mar 2025 13:33:40 +0100 Subject: [PATCH] Constrain memoryview type var to allowed types --- stdlib/builtins.pyi | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi index 4e2484509c1d..e466d2827529 100644 --- a/stdlib/builtins.pyi +++ b/stdlib/builtins.pyi @@ -76,7 +76,7 @@ if sys.version_info >= (3, 9): from types import GenericAlias _T = TypeVar("_T") -_I = TypeVar("_I", default=int) +_I = TypeVar("_I", int, bytes, float, bool, default=int) # possibly memoryview types _T_co = TypeVar("_T_co", covariant=True) _T_contra = TypeVar("_T_contra", contravariant=True) _R_co = TypeVar("_R_co", covariant=True) @@ -882,7 +882,7 @@ class memoryview(Sequence[_I]): @overload def cast(self, format: Literal["?"], shape: list[int] | tuple[int, ...] = ...) -> memoryview[bool]: ... @overload - def cast(self, format: _IntegerFormats, shape: list[int] | tuple[int, ...] = ...) -> memoryview: ... + def cast(self, format: _IntegerFormats, shape: list[int] | tuple[int, ...] = ...) -> memoryview[int]: ... @overload def __getitem__(self, key: SupportsIndex | tuple[SupportsIndex, ...], /) -> _I: ... @overload