1
- import sys
2
1
from collections .abc import Callable , Collection , Sequence
3
2
from typing import Any , Protocol , TypeAlias , runtime_checkable
4
- from typing_extensions import TypeVar
3
+ from typing_extensions import Buffer , TypeVar
5
4
6
5
import numpy as np
7
6
from numpy .dtypes import StringDType
@@ -10,12 +9,6 @@ from ._nbit_base import _64Bit
10
9
from ._nested_sequence import _NestedSequence
11
10
from ._shape import _Shape
12
11
13
- if sys .version_info >= (3 , 12 ):
14
- from collections .abc import Buffer as _Buffer
15
- else :
16
- class _Buffer (Protocol ):
17
- def __buffer__ (self , flags : int , / ) -> memoryview : ...
18
-
19
12
_T = TypeVar ("_T" )
20
13
_ScalarType = TypeVar ("_ScalarType" , bound = np .generic )
21
14
_ScalarType_co = TypeVar ("_ScalarType_co" , bound = np .generic , covariant = True )
@@ -55,7 +48,7 @@ _ArrayLike: TypeAlias = _SupportsArray[np.dtype[_ScalarType]] | _NestedSequence[
55
48
# and another one for the rest
56
49
_DualArrayLike : TypeAlias = _SupportsArray [_DType ] | _T | _NestedSequence [_T ] | _NestedSequence [_SupportsArray [_DType ]]
57
50
58
- ArrayLike : TypeAlias = _Buffer | _DualArrayLike [np .dtype [Any ], complex | str | bytes ]
51
+ ArrayLike : TypeAlias = _DualArrayLike [np .dtype [Any ], complex | str | bytes ] | Buffer
59
52
60
53
# `ArrayLike<X>_co`: array-like objects that can be coerced into `X`
61
54
# given the casting rules `same_kind`
0 commit comments