summaryrefslogtreecommitdiff
path: root/numpy/typing
diff options
context:
space:
mode:
Diffstat (limited to 'numpy/typing')
-rw-r--r--numpy/typing/__init__.py11
-rw-r--r--numpy/typing/_array_like.py8
-rw-r--r--numpy/typing/_callable.py12
-rw-r--r--numpy/typing/_scalars.py26
4 files changed, 50 insertions, 7 deletions
diff --git a/numpy/typing/__init__.py b/numpy/typing/__init__.py
index 86fd5e787..987aa39aa 100644
--- a/numpy/typing/__init__.py
+++ b/numpy/typing/__init__.py
@@ -90,6 +90,16 @@ since its usage is discouraged.
Please see : https://numpy.org/devdocs/reference/arrays.dtypes.html
"""
+from ._scalars import (
+ _CharLike,
+ _BoolLike,
+ _IntLike,
+ _FloatLike,
+ _ComplexLike,
+ _NumberLike,
+ _ScalarLike,
+ _VoidLike,
+)
from ._array_like import _SupportsArray, ArrayLike
from ._shape import _Shape, _ShapeLike
from ._dtype_like import DtypeLike
@@ -97,4 +107,3 @@ from ._dtype_like import DtypeLike
from numpy._pytesttester import PytestTester
test = PytestTester(__name__)
del PytestTester
-
diff --git a/numpy/typing/_array_like.py b/numpy/typing/_array_like.py
index 76c0c839c..1c00b200f 100644
--- a/numpy/typing/_array_like.py
+++ b/numpy/typing/_array_like.py
@@ -2,6 +2,7 @@ import sys
from typing import Any, overload, Sequence, TYPE_CHECKING, Union
from numpy import ndarray
+from ._scalars import _ScalarLike
from ._dtype_like import DtypeLike
if sys.version_info >= (3, 8):
@@ -31,4 +32,9 @@ else:
# is resolved. See also the mypy issue:
#
# https://github.com/python/typing/issues/593
-ArrayLike = Union[bool, int, float, complex, _SupportsArray, Sequence]
+ArrayLike = Union[
+ _ScalarLike,
+ Sequence[_ScalarLike],
+ Sequence[Sequence[Any]], # TODO: Wait for support for recursive types
+ _SupportsArray,
+]
diff --git a/numpy/typing/_callable.py b/numpy/typing/_callable.py
index 5e14b708f..0d876ae8d 100644
--- a/numpy/typing/_callable.py
+++ b/numpy/typing/_callable.py
@@ -12,11 +12,6 @@ import sys
from typing import Union, TypeVar, overload, Any
from numpy import (
- _BoolLike,
- _IntLike,
- _FloatLike,
- _ComplexLike,
- _NumberLike,
generic,
bool_,
timedelta64,
@@ -32,6 +27,13 @@ from numpy import (
complexfloating,
complex128,
)
+from ._scalars import (
+ _BoolLike,
+ _IntLike,
+ _FloatLike,
+ _ComplexLike,
+ _NumberLike,
+)
if sys.version_info >= (3, 8):
from typing import Protocol
diff --git a/numpy/typing/_scalars.py b/numpy/typing/_scalars.py
new file mode 100644
index 000000000..e4fc28b07
--- /dev/null
+++ b/numpy/typing/_scalars.py
@@ -0,0 +1,26 @@
+from typing import Union, Tuple, Any
+
+import numpy as np
+
+# NOTE: `_StrLike` and `_BytesLike` are pointless, as `np.str_` and `np.bytes_`
+# are already subclasses of their builtin counterpart
+
+_CharLike = Union[str, bytes]
+
+_BoolLike = Union[bool, np.bool_]
+_IntLike = Union[int, np.integer]
+_FloatLike = Union[_IntLike, float, np.floating]
+_ComplexLike = Union[_FloatLike, complex, np.complexfloating]
+_NumberLike = Union[int, float, complex, np.number, np.bool_]
+
+_ScalarLike = Union[
+ int,
+ float,
+ complex,
+ str,
+ bytes,
+ np.generic,
+]
+
+# `_VoidLike` is technically not a scalar, but it's close enough
+_VoidLike = Union[Tuple[Any, ...], np.void]