@@ -23,10 +23,9 @@ from typing import (
2323 TypedDict ,
2424 final ,
2525 overload ,
26- runtime_checkable ,
2726 type_check_only ,
2827)
29- from typing_extensions import CapsuleType , LiteralString , Never , Protocol , Self , TypeVar , Unpack , deprecated , override
28+ from typing_extensions import Buffer , CapsuleType , LiteralString , Never , Protocol , Self , TypeVar , Unpack , deprecated , override
3029
3130from . import (
3231 __config__ as __config__ ,
@@ -463,22 +462,6 @@ from .lib._utils_impl import get_include, info, show_runtime
463462from .matrixlib import asmatrix , bmat , matrix
464463from .version import __version__
465464
466- @runtime_checkable
467- class _Buffer (Protocol ):
468- def __buffer__ (self , flags : int , / ) -> memoryview : ...
469-
470- if sys .version_info >= (3 , 12 ):
471- _SupportsBuffer : TypeAlias = _Buffer
472- else :
473- import array as _array
474- import mmap as _mmap
475-
476- from numpy import distutils as distutils # noqa: ICN003
477-
478- _SupportsBuffer : TypeAlias = (
479- _Buffer | bytes | bytearray | memoryview | _array .array [Any ] | _mmap .mmap | NDArray [Any ] | generic
480- )
481-
482465__all__ = [ # noqa: RUF022
483466 # __numpy_submodules__
484467 "char" , "core" , "ctypeslib" , "dtypes" , "exceptions" , "f2py" , "fft" , "lib" , "linalg" , "ma" , "polynomial" , "random" , "rec" ,
@@ -1561,8 +1544,8 @@ class _ArrayOrScalarCommon:
15611544 @property
15621545 def device (self ) -> _Device : ...
15631546
1564- if sys . version_info >= ( 3 , 12 ):
1565- def __buffer__ (self , flags : int , / ) -> memoryview : ...
1547+ # typeshed forces us to lie about this on python<3.12
1548+ def __buffer__ (self , flags : int , / ) -> memoryview : ...
15661549
15671550 #
15681551 @property
@@ -1993,7 +1976,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
19931976 cls ,
19941977 shape : _ShapeLike ,
19951978 dtype : DTypeLike = float , # noqa: PYI011
1996- buffer : _SupportsBuffer | None = None ,
1979+ buffer : Buffer | None = None ,
19971980 offset : CanIndex = 0 ,
19981981 strides : _ShapeLike | None = None ,
19991982 order : _OrderKACF | None = None ,
@@ -2107,7 +2090,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
21072090 @overload # == 1-d
21082091 def __iter__ (self : ndarray [tuple [int ], dtype [_ScalarT ]], / ) -> Iterator [_ScalarT ]: ...
21092092 @overload # >= 2-d
2110- def __iter__ (self : ndarray [tuple [int , int , * tuple [int , ...]], dtype [_ScalarT ]], / ) -> Iterator [NDArray [_ScalarT ]]: ...
2093+ def __iter__ (self : ndarray [tuple [int , int , Unpack [ tuple [int , ...] ]], dtype [_ScalarT ]], / ) -> Iterator [NDArray [_ScalarT ]]: ...
21112094 @overload # ?-d
21122095 def __iter__ (self , / ) -> Iterator [Any ]: ...
21132096
@@ -3836,9 +3819,6 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
38363819 @abc .abstractmethod
38373820 def __init__ (self , / , * args : Any , ** kwargs : Any ) -> None : ...
38383821
3839- if sys .version_info >= (3 , 12 ):
3840- def __buffer__ (self , flags : int , / ) -> memoryview : ...
3841-
38423822 #
38433823 @overload
38443824 def __array__ (self , dtype : None = None , / ) -> ndarray [tuple [()], dtype [Self ]]: ...
@@ -4083,7 +4063,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
40834063 * sizes6_ : CanIndex ,
40844064 order : _OrderACF = "C" ,
40854065 copy : py_bool | None = None ,
4086- ) -> ndarray [tuple [L [1 ], L [1 ], L [1 ], L [1 ], L [1 ], * tuple [L [1 ], ...]], dtype [Self ]]: ...
4066+ ) -> ndarray [tuple [L [1 ], L [1 ], L [1 ], L [1 ], L [1 ], Unpack [ tuple [L [1 ], ...] ]], dtype [Self ]]: ...
40874067
40884068 #
40894069 @overload
@@ -6557,9 +6537,6 @@ class bytes_(character[bytes], bytes): # type: ignore[misc]
65576537 @overload
65586538 def __init__ (self , s : str , / , encoding : str , errors : str = ...) -> None : ...
65596539
6560- #
6561- def __bytes__ (self , / ) -> bytes : ...
6562-
65636540class str_ (character [str ], str ): # type: ignore[misc]
65646541 @overload
65656542 def __new__ (cls , value : object = ..., / ) -> Self : ...
0 commit comments