@@ -913,8 +913,6 @@ class dtype(Generic[_DTypeScalar]):
913
913
@property
914
914
def type (self ) -> Type [generic ]: ...
915
915
916
- _DType = dtype # to avoid name conflicts with ndarray.dtype
917
-
918
916
class _flagsobj :
919
917
aligned : bool
920
918
updateifcopy : bool
@@ -1441,10 +1439,16 @@ class _ArrayOrScalarCommon:
1441
1439
keepdims : bool = ...,
1442
1440
) -> _NdArraySubClass : ...
1443
1441
1442
+ _DType = TypeVar ("_DType" , bound = dtype [Any ])
1443
+
1444
+ # TODO: Set the `bound` to something more suitable once we
1445
+ # have proper shape support
1446
+ _ShapeType = TypeVar ("_ShapeType" , bound = Any )
1447
+
1444
1448
_BufferType = Union [ndarray , bytes , bytearray , memoryview ]
1445
1449
_Casting = Literal ["no" , "equiv" , "safe" , "same_kind" , "unsafe" ]
1446
1450
1447
- class ndarray (_ArrayOrScalarCommon , Iterable , Sized , Container ):
1451
+ class ndarray (_ArrayOrScalarCommon , Generic [ _ShapeType , _DType ] ):
1448
1452
@property
1449
1453
def base (self ) -> Optional [ndarray ]: ...
1450
1454
@property
@@ -1469,8 +1473,6 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
1469
1473
order : _OrderKACF = ...,
1470
1474
) -> _ArraySelf : ...
1471
1475
@property
1472
- def dtype (self ) -> _DType : ...
1473
- @property
1474
1476
def ctypes (self ) -> _ctypes : ...
1475
1477
@property
1476
1478
def shape (self ) -> _Shape : ...
@@ -1625,6 +1627,9 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
1625
1627
def __iand__ (self : _ArraySelf , other : ArrayLike ) -> _ArraySelf : ...
1626
1628
def __ixor__ (self : _ArraySelf , other : ArrayLike ) -> _ArraySelf : ...
1627
1629
def __ior__ (self : _ArraySelf , other : ArrayLike ) -> _ArraySelf : ...
1630
+ # Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
1631
+ @property
1632
+ def dtype (self ) -> _DType : ...
1628
1633
1629
1634
# NOTE: while `np.generic` is not technically an instance of `ABCMeta`,
1630
1635
# the `@abstractmethod` decorator is herein used to (forcefully) deny
@@ -1644,8 +1649,6 @@ class generic(_ArrayOrScalarCommon):
1644
1649
@property
1645
1650
def base (self ) -> None : ...
1646
1651
@property
1647
- def dtype (self : _ScalarType ) -> _DType [_ScalarType ]: ...
1648
- @property
1649
1652
def ndim (self ) -> Literal [0 ]: ...
1650
1653
@property
1651
1654
def size (self ) -> Literal [1 ]: ...
@@ -1664,6 +1667,9 @@ class generic(_ArrayOrScalarCommon):
1664
1667
self : _ScalarType , axis : Union [Literal [0 ], Tuple [()]] = ...
1665
1668
) -> _ScalarType : ...
1666
1669
def transpose (self : _ScalarType , __axes : Tuple [()] = ...) -> _ScalarType : ...
1670
+ # Keep `dtype` at the bottom to avoid name conflicts with `np.dtype`
1671
+ @property
1672
+ def dtype (self : _ScalarType ) -> dtype [_ScalarType ]: ...
1667
1673
1668
1674
class number (generic , Generic [_NBit_co ]): # type: ignore
1669
1675
@property
0 commit comments