@@ -283,7 +283,16 @@ class _ArrayOrScalarCommon(
283283
284284_BufferType = Union [ndarray , bytes , bytearray , memoryview ]
285285
286- class ndarray (_ArrayOrScalarCommon , Iterable , Sized , Container ):
286+ _ArbitraryDtype = TypeVar ('_ArbitraryDtype' , bound = generic )
287+ _ArrayDtype = TypeVar ('_ArrayDtype' , bound = generic )
288+
289+ class ndarray (
290+ Generic [_ArrayDtype ],
291+ _ArrayOrScalarCommon ,
292+ Iterable ,
293+ Sized ,
294+ Container ,
295+ ):
287296 real : ndarray
288297 imag : ndarray
289298 def __new__ (
@@ -296,7 +305,7 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
296305 order : Optional [str ] = ...,
297306 ) -> ndarray : ...
298307 @property
299- def dtype (self ) -> _Dtype : ...
308+ def dtype (self ) -> Type [ _ArrayDtype ] : ...
300309 @property
301310 def ctypes (self ) -> _ctypes : ...
302311 @property
@@ -326,6 +335,16 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
326335 ) -> None : ...
327336 def dump (self , file : str ) -> None : ...
328337 def dumps (self ) -> bytes : ...
338+ @overload
339+ def astype (
340+ self ,
341+ dtype : _ArbitraryDtype ,
342+ order : str = ...,
343+ casting : str = ...,
344+ subok : bool = ...,
345+ copy : bool = ...,
346+ ) -> ndarray [_ArbitraryDtype ]: ...
347+ @overload
329348 def astype (
330349 self ,
331350 dtype : _DtypeLike ,
@@ -334,40 +353,74 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
334353 subok : bool = ...,
335354 copy : bool = ...,
336355 ) -> ndarray : ...
337- def byteswap (self , inplace : bool = ...) -> ndarray : ...
338- def copy (self , order : str = ...) -> ndarray : ...
356+ def byteswap (self , inplace : bool = ...) -> ndarray [_ArrayDtype ]: ...
357+ @overload
358+ def copy (self ) -> ndarray [_ArrayDtype ]: ...
359+ @overload
360+ def copy (self , order : str = ...) -> ndarray [_ArrayDtype ]: ...
361+ @overload
362+ def view (self ) -> ndarray [_ArrayDtype ]: ...
339363 @overload
340364 def view (self , dtype : Type [_NdArraySubClass ]) -> _NdArraySubClass : ...
341365 @overload
366+ def view (self , dtype : Type [_ArbitraryDtype ]) -> ndarray [_ArbitraryDtype ]: ...
367+ @overload
342368 def view (self , dtype : _DtypeLike = ...) -> ndarray : ...
343369 @overload
344370 def view (
345- self , dtype : _DtypeLike , type : Type [_NdArraySubClass ]
371+ self ,
372+ dtype : _ArbitraryDtype ,
373+ type : Type [_NdarraySubClass ],
374+ ) -> _NdArraySubClass [_ArbitraryDtype ]: ...
375+ @overload
376+ def view (
377+ self ,
378+ dtype : _DtypeLike ,
379+ type : Type [_NdArraySubClass ],
346380 ) -> _NdArraySubClass : ...
347381 @overload
348382 def view (self , * , type : Type [_NdArraySubClass ]) -> _NdArraySubClass : ...
383+ @overload
384+ def getfield (
385+ self ,
386+ dtype : Type [_ArbitraryDtype ],
387+ offset : int = ...,
388+ ) -> ndarray [_ArbitraryDtype ]: ...
389+ @overload
349390 def getfield (self , dtype : Union [_DtypeLike , str ], offset : int = ...) -> ndarray : ...
350391 def setflags (
351392 self , write : bool = ..., align : bool = ..., uic : bool = ...
352393 ) -> None : ...
353394 def fill (self , value : Any ) -> None : ...
354395 # Shape manipulation
355396 @overload
356- def reshape (self , shape : Sequence [int ], * , order : str = ...) -> ndarray : ...
397+ def reshape (
398+ self ,
399+ shape : Sequence [int ],
400+ * ,
401+ order : str = ...,
402+ ) -> ndarray [_ArrayDtype ]: ...
357403 @overload
358- def reshape (self , * shape : int , order : str = ...) -> ndarray : ...
404+ def reshape (
405+ self ,
406+ * shape : int ,
407+ order : str = ...,
408+ ) -> ndarray [_ArrayDtype ]: ...
359409 @overload
360410 def resize (self , new_shape : Sequence [int ], * , refcheck : bool = ...) -> None : ...
361411 @overload
362412 def resize (self , * new_shape : int , refcheck : bool = ...) -> None : ...
363413 @overload
364- def transpose (self , axes : Sequence [int ]) -> ndarray : ...
414+ def transpose (self , axes : Sequence [int ]) -> ndarray [ _ArrayDtype ] : ...
365415 @overload
366- def transpose (self , * axes : int ) -> ndarray : ...
367- def swapaxes (self , axis1 : int , axis2 : int ) -> ndarray : ...
368- def flatten (self , order : str = ...) -> ndarray : ...
369- def ravel (self , order : str = ...) -> ndarray : ...
370- def squeeze (self , axis : Union [int , Tuple [int , ...]] = ...) -> ndarray : ...
416+ def transpose (self , * axes : int ) -> ndarray [_ArrayDtype ]: ...
417+ def swapaxes (self , axis1 : int , axis2 : int ) -> ndarray [_ArrayDtype ]: ...
418+ def flatten (self , order : str = ...) -> ndarray [_ArrayDtype ]: ...
419+ def ravel (self , order : str = ...) -> ndarray [_ArrayDtype ]: ...
420+ def squeeze (
421+ self ,
422+ axis : Union [int , Tuple [int , ...]] = ...,
423+ ) -> ndarray [_ArrayDtype ]: ...
371424 # Many of these special methods are irrelevant currently, since protocols
372425 # aren't supported yet. That said, I'm adding them for completeness.
373426 # https://docs.python.org/3/reference/datamodel.html
@@ -472,6 +525,15 @@ class str_(character): ...
472525# float128, complex256
473526# float96
474527
528+ @overload
529+ def array (
530+ object : object ,
531+ dtype : Type [_ArbitraryDtype ] = ...,
532+ copy : bool = ...,
533+ subok : bool = ...,
534+ ndmin : int = ...,
535+ ) -> ndarray [_ArbitraryDtype ]: ...
536+ @overload
475537def array (
476538 object : object ,
477539 dtype : _DtypeLike = ...,
0 commit comments