@@ -75,6 +75,7 @@ if sys.version_info >= (3, 9):
75
75
from types import GenericAlias
76
76
77
77
_T = TypeVar ("_T" )
78
+ _I = TypeVar ("_I" , default = int )
78
79
_T_co = TypeVar ("_T_co" , covariant = True )
79
80
_T_contra = TypeVar ("_T_contra" , contravariant = True )
80
81
_R_co = TypeVar ("_R_co" , covariant = True )
@@ -823,8 +824,12 @@ class bytearray(MutableSequence[int]):
823
824
def __buffer__ (self , flags : int , / ) -> memoryview : ...
824
825
def __release_buffer__ (self , buffer : memoryview , / ) -> None : ...
825
826
827
+ _IntegerFormats : TypeAlias = Literal [
828
+ "b" , "B" , "@b" , "@B" , "h" , "H" , "@h" , "@H" , "i" , "I" , "@i" , "@I" , "l" , "L" , "@l" , "@L" , "q" , "Q" , "@q" , "@Q" , "P" , "@P"
829
+ ]
830
+
826
831
@final
827
- class memoryview (Sequence [int ]):
832
+ class memoryview (Sequence [_I ]):
828
833
@property
829
834
def format (self ) -> str : ...
830
835
@property
@@ -854,13 +859,20 @@ class memoryview(Sequence[int]):
854
859
def __exit__ (
855
860
self , exc_type : type [BaseException ] | None , exc_val : BaseException | None , exc_tb : TracebackType | None , /
856
861
) -> None : ...
857
- def cast (self , format : str , shape : list [int ] | tuple [int , ...] = ...) -> memoryview : ...
858
862
@overload
859
- def __getitem__ (self , key : SupportsIndex | tuple [SupportsIndex , ...], / ) -> int : ...
863
+ def cast (self , format : Literal ["c" , "@c" ], shape : list [int ] | tuple [int , ...] = ...) -> memoryview [bytes ]: ...
864
+ @overload
865
+ def cast (self , format : Literal ["f" , "@f" , "d" , "@d" ], shape : list [int ] | tuple [int , ...] = ...) -> memoryview [float ]: ...
866
+ @overload
867
+ def cast (self , format : Literal ["?" ], shape : list [int ] | tuple [int , ...] = ...) -> memoryview [bool ]: ...
860
868
@overload
861
- def __getitem__ (self , key : slice , / ) -> memoryview : ...
869
+ def cast (self , format : _IntegerFormats , shape : list [int ] | tuple [int , ...] = ...) -> memoryview : ...
870
+ @overload
871
+ def __getitem__ (self , key : SupportsIndex | tuple [SupportsIndex , ...], / ) -> _I : ...
872
+ @overload
873
+ def __getitem__ (self , key : slice , / ) -> memoryview [_I ]: ...
862
874
def __contains__ (self , x : object , / ) -> bool : ...
863
- def __iter__ (self ) -> Iterator [int ]: ...
875
+ def __iter__ (self ) -> Iterator [_I ]: ...
864
876
def __len__ (self ) -> int : ...
865
877
def __eq__ (self , value : object , / ) -> bool : ...
866
878
def __hash__ (self ) -> int : ...
0 commit comments