@@ -23,10 +23,9 @@ from typing import (
23
23
TypedDict ,
24
24
final ,
25
25
overload ,
26
- runtime_checkable ,
27
26
type_check_only ,
28
27
)
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
30
29
31
30
from . import (
32
31
__config__ as __config__ ,
@@ -463,22 +462,6 @@ from .lib._utils_impl import get_include, info, show_runtime
463
462
from .matrixlib import asmatrix , bmat , matrix
464
463
from .version import __version__
465
464
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
-
482
465
__all__ = [ # noqa: RUF022
483
466
# __numpy_submodules__
484
467
"char" , "core" , "ctypeslib" , "dtypes" , "exceptions" , "f2py" , "fft" , "lib" , "linalg" , "ma" , "polynomial" , "random" , "rec" ,
@@ -1561,8 +1544,8 @@ class _ArrayOrScalarCommon:
1561
1544
@property
1562
1545
def device (self ) -> _Device : ...
1563
1546
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 : ...
1566
1549
1567
1550
#
1568
1551
@property
@@ -1993,7 +1976,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
1993
1976
cls ,
1994
1977
shape : _ShapeLike ,
1995
1978
dtype : DTypeLike = float , # noqa: PYI011
1996
- buffer : _SupportsBuffer | None = None ,
1979
+ buffer : Buffer | None = None ,
1997
1980
offset : CanIndex = 0 ,
1998
1981
strides : _ShapeLike | None = None ,
1999
1982
order : _OrderKACF | None = None ,
@@ -2107,7 +2090,7 @@ class ndarray(_ArrayOrScalarCommon, Generic[_ShapeT_co, _DTypeT_co]):
2107
2090
@overload # == 1-d
2108
2091
def __iter__ (self : ndarray [tuple [int ], dtype [_ScalarT ]], / ) -> Iterator [_ScalarT ]: ...
2109
2092
@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 ]]: ...
2111
2094
@overload # ?-d
2112
2095
def __iter__ (self , / ) -> Iterator [Any ]: ...
2113
2096
@@ -3836,9 +3819,6 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
3836
3819
@abc .abstractmethod
3837
3820
def __init__ (self , / , * args : Any , ** kwargs : Any ) -> None : ...
3838
3821
3839
- if sys .version_info >= (3 , 12 ):
3840
- def __buffer__ (self , flags : int , / ) -> memoryview : ...
3841
-
3842
3822
#
3843
3823
@overload
3844
3824
def __array__ (self , dtype : None = None , / ) -> ndarray [tuple [()], dtype [Self ]]: ...
@@ -4083,7 +4063,7 @@ class generic(_ArrayOrScalarCommon, Generic[_ItemT_co]):
4083
4063
* sizes6_ : CanIndex ,
4084
4064
order : _OrderACF = "C" ,
4085
4065
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 ]]: ...
4087
4067
4088
4068
#
4089
4069
@overload
@@ -6557,9 +6537,6 @@ class bytes_(character[bytes], bytes): # type: ignore[misc]
6557
6537
@overload
6558
6538
def __init__ (self , s : str , / , encoding : str , errors : str = ...) -> None : ...
6559
6539
6560
- #
6561
- def __bytes__ (self , / ) -> bytes : ...
6562
-
6563
6540
class str_ (character [str ], str ): # type: ignore[misc]
6564
6541
@overload
6565
6542
def __new__ (cls , value : object = ..., / ) -> Self : ...
0 commit comments