summaryrefslogtreecommitdiff
path: root/numpy/core
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2021-02-24 00:49:52 +0100
committerBas van Beek <b.f.van.beek@vu.nl>2021-04-20 14:37:22 +0200
commit83c420f9d0a81e546b61af36392c4cbddcd727a6 (patch)
tree14c18de547622053f5acea61a459c4854db44d58 /numpy/core
parent3e8b865690457abf8ec710e2fd867476432bea73 (diff)
downloadnumpy-83c420f9d0a81e546b61af36392c4cbddcd727a6.tar.gz
ENH: Add annotations for 4 objects in `np.core.numerictypes`
* `cast` * `nbytes` * `ScalarType` * `typecodes`
Diffstat (limited to 'numpy/core')
-rw-r--r--numpy/core/numerictypes.pyi56
1 files changed, 52 insertions, 4 deletions
diff --git a/numpy/core/numerictypes.pyi b/numpy/core/numerictypes.pyi
index c8b4e1c65..1c9c84e95 100644
--- a/numpy/core/numerictypes.pyi
+++ b/numpy/core/numerictypes.pyi
@@ -1,9 +1,55 @@
-from typing import TypeVar, Optional, Type, Union, Tuple, Sequence, overload, Any
+import sys
+from typing import (
+ TypeVar,
+ Optional,
+ Type,
+ Union,
+ Tuple,
+ Sequence,
+ overload,
+ Any,
+ TypeVar,
+ Dict,
+ List,
+)
from numpy import generic, ndarray, dtype
-from numpy.typing import DTypeLike
+
+from numpy.core._type_aliases import (
+ sctypeDict as sctypeDict,
+ sctypes as sctypes,
+)
+
+from numpy.typing import DTypeLike, ArrayLike
+
+if sys.version_info >= (3, 8):
+ from typing import Literal, Protocol, TypedDict
+else:
+ from typing_extensions import Literal, Protocol, TypedDict
_T = TypeVar("_T")
+_ScalarType = TypeVar("_ScalarType", bound=generic)
+
+class _CastFunc(Protocol):
+ def __call__(
+ self, x: ArrayLike, k: DTypeLike = ...
+ ) -> ndarray[Any, dtype[Any]]: ...
+
+class _TypeCodes(TypedDict):
+ Character: Literal['c']
+ Integer: Literal['bhilqp']
+ UnsignedInteger: Literal['BHILQP']
+ Float: Literal['efdg']
+ Complex: Literal['FDG']
+ AllInteger: Literal['bBhHiIlLqQpP']
+ AllFloat: Literal['efdgFDG']
+ Datetime: Literal['Mm']
+ All: Literal['?bhilqpBHILQPefdgFDGSUVOMm']
+
+class _typedict(Dict[Type[generic], _T]):
+ def __getitem__(self, key: DTypeLike) -> _T: ...
+
+__all__: List[str]
def maximum_sctype(t: DTypeLike) -> dtype: ...
def issctype(rep: object) -> bool: ...
@@ -25,5 +71,7 @@ def find_common_type(
array_types: Sequence[DTypeLike], scalar_types: Sequence[DTypeLike]
) -> dtype: ...
-# TODO: Add annotations for the following objects:
-# nbytes, cast, ScalarType & typecodes
+cast: _typedict[_CastFunc]
+nbytes: _typedict[int]
+typecodes: _TypeCodes
+ScalarType: Tuple[type, ...]