summaryrefslogtreecommitdiff
path: root/numpy/_typing/_scalars.py
diff options
context:
space:
mode:
authorCharles Harris <charlesr.harris@gmail.com>2022-03-25 09:40:49 -0600
committerGitHub <noreply@github.com>2022-03-25 09:40:49 -0600
commit266aad7478bc7fbcc55eea7f942a0d373b838396 (patch)
tree0f144df0739b772bf1a38b3e03463c6b4eb21d91 /numpy/_typing/_scalars.py
parent4115eead62a382a32afdb0450c54e0249db02915 (diff)
parent65ec64c932626689b50b53e0909ced47f5a821fa (diff)
downloadnumpy-266aad7478bc7fbcc55eea7f942a0d373b838396.tar.gz
Merge pull request #21216 from BvB93/_typing
MAINT: Split `numpy.typing` into a public and private component
Diffstat (limited to 'numpy/_typing/_scalars.py')
-rw-r--r--numpy/_typing/_scalars.py30
1 files changed, 30 insertions, 0 deletions
diff --git a/numpy/_typing/_scalars.py b/numpy/_typing/_scalars.py
new file mode 100644
index 000000000..516b996dc
--- /dev/null
+++ b/numpy/_typing/_scalars.py
@@ -0,0 +1,30 @@
+from typing import Union, Tuple, Any
+
+import numpy as np
+
+# NOTE: `_StrLike_co` and `_BytesLike_co` are pointless, as `np.str_` and
+# `np.bytes_` are already subclasses of their builtin counterpart
+
+_CharLike_co = Union[str, bytes]
+
+# The 6 `<X>Like_co` type-aliases below represent all scalars that can be
+# coerced into `<X>` (with the casting rule `same_kind`)
+_BoolLike_co = Union[bool, np.bool_]
+_UIntLike_co = Union[_BoolLike_co, np.unsignedinteger]
+_IntLike_co = Union[_BoolLike_co, int, np.integer]
+_FloatLike_co = Union[_IntLike_co, float, np.floating]
+_ComplexLike_co = Union[_FloatLike_co, complex, np.complexfloating]
+_TD64Like_co = Union[_IntLike_co, np.timedelta64]
+
+_NumberLike_co = Union[int, float, complex, np.number, np.bool_]
+_ScalarLike_co = Union[
+ int,
+ float,
+ complex,
+ str,
+ bytes,
+ np.generic,
+]
+
+# `_VoidLike_co` is technically not a scalar, but it's close enough
+_VoidLike_co = Union[Tuple[Any, ...], np.void]