1
1
import builtins
2
2
import sys
3
3
import datetime as dt
4
+ from abc import abstractmethod , ABCMeta
4
5
5
6
from numpy .core ._internal import _ctypes
6
7
from numpy .typing import ArrayLike , DtypeLike , _Shape , _ShapeLike
@@ -359,22 +360,33 @@ class ndarray(_ArrayOrScalarCommon, Iterable, Sized, Container):
359
360
def __contains__ (self , key ) -> bool : ...
360
361
def __index__ (self ) -> int : ...
361
362
363
+ # NOTE: while `np.generic` is not technically an instance of `ABCMeta`,
364
+ # the `@abstractmethod` decorator is herein used to (forcefully) deny
365
+ # the creation of `np.generic` instances.
366
+ # The `# type: ignore` comments are necessary to silence mypy errors regarding
367
+ # the missing `ABCMeta` metaclass.
368
+
369
+ # See https://github.com/numpy/numpy-stubs/pull/80 for more details.
370
+
362
371
class generic (_ArrayOrScalarCommon ):
363
- def __init__ (self , value : Any = ...) -> None : ...
372
+ @abstractmethod
373
+ def __init__ (self , * args : Any , ** kwargs : Any ) -> None : ...
364
374
@property
365
375
def base (self ) -> None : ...
366
376
367
- class _real_generic (generic ):
377
+ class _real_generic (generic ): # type: ignore
368
378
@property
369
379
def real (self : _ArraySelf ) -> _ArraySelf : ...
370
380
@property
371
381
def imag (self : _ArraySelf ) -> _ArraySelf : ...
372
382
373
- class number (generic ):
374
- def __init__ (self , value : Union [SupportsInt , SupportsFloat ] = ...) -> None : ...
383
+ class number (generic ): ... # type: ignore
384
+
385
+ class bool_ (_real_generic ):
386
+ def __init__ (self , value : object = ...) -> None : ...
375
387
376
- class bool_ ( _real_generic ): ...
377
- class object_ ( generic ) : ...
388
+ class object_ ( generic ):
389
+ def __init__ ( self , value : object = ...) -> None : ...
378
390
379
391
class datetime64 :
380
392
@overload
@@ -386,8 +398,8 @@ class datetime64:
386
398
def __add__ (self , other : Union [timedelta64 , int ]) -> datetime64 : ...
387
399
def __sub__ (self , other : Union [timedelta64 , datetime64 , int ]) -> timedelta64 : ...
388
400
389
- class integer (number , _real_generic ): ...
390
- class signedinteger (integer ): ...
401
+ class integer (number , _real_generic ): ... # type: ignore
402
+ class signedinteger (integer ): ... # type: ignore
391
403
392
404
class int8 (signedinteger ):
393
405
def __init__ (self , value : SupportsInt = ...) -> None : ...
@@ -419,7 +431,7 @@ class timedelta64(signedinteger):
419
431
def __truediv__ (self , other : float ) -> timedelta64 : ...
420
432
def __mod__ (self , other : timedelta64 ) -> timedelta64 : ...
421
433
422
- class unsignedinteger (integer ): ...
434
+ class unsignedinteger (integer ): ... # type: ignore
423
435
424
436
class uint8 (unsignedinteger ):
425
437
def __init__ (self , value : SupportsInt = ...) -> None : ...
@@ -433,34 +445,60 @@ class uint32(unsignedinteger):
433
445
class uint64 (unsignedinteger ):
434
446
def __init__ (self , value : SupportsInt = ...) -> None : ...
435
447
436
- class inexact (number ): ...
437
- class floating (inexact , _real_generic ): ...
438
- class float16 (floating ): ...
439
- class float32 (floating ): ...
440
- class float64 (floating ): ...
448
+ class inexact (number ): ... # type: ignore
449
+ class floating (inexact , _real_generic ): ... # type: ignore
441
450
442
- class complexfloating (inexact ):
443
- def __init__ (
444
- self , value : Union [SupportsInt , SupportsFloat , SupportsComplex , complex ] = ...
445
- ) -> None : ...
451
+ class float16 (floating ):
452
+ def __init__ (self , value : SupportsFloat = ...) -> None : ...
453
+
454
+ class float32 (floating ):
455
+ def __init__ (self , value : SupportsFloat = ...) -> None : ...
456
+
457
+ class float64 (floating ):
458
+ def __init__ (self , value : SupportsFloat = ...) -> None : ...
459
+
460
+ class complexfloating (inexact ): ... # type: ignore
446
461
447
462
class complex64 (complexfloating ):
463
+ def __init__ (
464
+ self , value : Union [SupportsInt , SupportsFloat , SupportsComplex ] = ...
465
+ ) -> None : ...
448
466
@property
449
467
def real (self ) -> float32 : ...
450
468
@property
451
469
def imag (self ) -> float32 : ...
452
470
453
471
class complex128 (complexfloating ):
472
+ def __init__ (
473
+ self , value : Union [SupportsInt , SupportsFloat , SupportsComplex ] = ...
474
+ ) -> None : ...
454
475
@property
455
476
def real (self ) -> float64 : ...
456
477
@property
457
478
def imag (self ) -> float64 : ...
458
479
459
- class flexible (_real_generic ): ...
460
- class void (flexible ): ...
461
- class character (_real_generic ): ...
462
- class bytes_ (character ): ...
463
- class str_ (character ): ...
480
+ class flexible (_real_generic ): ... # type: ignore
481
+
482
+ class void (flexible ):
483
+ def __init__ (self , value : Union [int , integer , bool_ , bytes , bytes_ ]): ...
484
+
485
+ class character (_real_generic ): ... # type: ignore
486
+
487
+ class bytes_ (character ):
488
+ @overload
489
+ def __init__ (self , value : object = ...) -> None : ...
490
+ @overload
491
+ def __init__ (
492
+ self , value : object , encoding : str = ..., errors : str = ...
493
+ ) -> None : ...
494
+
495
+ class str_ (character ):
496
+ @overload
497
+ def __init__ (self , value : object = ...) -> None : ...
498
+ @overload
499
+ def __init__ (
500
+ self , value : object , encoding : str = ..., errors : str = ...
501
+ ) -> None : ...
464
502
465
503
# TODO(alan): Platform dependent types
466
504
# longcomplex, longdouble, longfloat
0 commit comments