From fd01786ea4c7dde540cede258ad11d08d25bacfc Mon Sep 17 00:00:00 2001 From: Bas van Beek <43369155+BvB93@users.noreply.github.com> Date: Wed, 7 Oct 2020 18:53:33 +0200 Subject: MAINT: Move aliases for common scalar unions to `numpy.typing` (#17429) * MAINT: Move the `Like` unions to `numpy.typing` --- numpy/typing/_scalars.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 numpy/typing/_scalars.py (limited to 'numpy/typing/_scalars.py') 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] -- cgit v1.2.1