summaryrefslogtreecommitdiff
path: root/numpy/typing/_char_codes.py
diff options
context:
space:
mode:
authorBas van Beek <b.f.van.beek@vu.nl>2020-11-16 19:08:49 +0100
committerBas van Beek <b.f.van.beek@vu.nl>2020-12-22 17:24:04 +0100
commitedacfda3da401c56f1eb32d58de08581e03f84d6 (patch)
tree4a4e73a2570317ff9c52306930bf3bafdd81406c /numpy/typing/_char_codes.py
parenta5285349805c5e794700a3dfcb378b391c53b0c8 (diff)
downloadnumpy-edacfda3da401c56f1eb32d58de08581e03f84d6.tar.gz
ENH: Centralize all `DTypeLike` string aliases in `numpy.typing`
Diffstat (limited to 'numpy/typing/_char_codes.py')
-rw-r--r--numpy/typing/_char_codes.py115
1 files changed, 115 insertions, 0 deletions
diff --git a/numpy/typing/_char_codes.py b/numpy/typing/_char_codes.py
new file mode 100644
index 000000000..7e5b82cfa
--- /dev/null
+++ b/numpy/typing/_char_codes.py
@@ -0,0 +1,115 @@
+import sys
+from typing import Any, TYPE_CHECKING
+
+if sys.version_info >= (3, 8):
+ from typing import Literal
+ HAVE_LITERAL = True
+else:
+ try:
+ from typing_extensions import Literal
+ except ImportError:
+ HAVE_LITERAL = False
+ else:
+ HAVE_LITERAL = True
+
+if TYPE_CHECKING or HAVE_LITERAL:
+ _BoolCodes = Literal["?", "=?", "<?", ">?", "bool", "bool_", "bool8"]
+
+ _UInt8Codes = Literal["uint8", "u1", "=u1", "<u1", ">u1"]
+ _UInt16Codes = Literal["uint16", "u2", "=u2", "<u2", ">u2"]
+ _UInt32Codes = Literal["uint32", "u4", "=u4", "<u4", ">u4"]
+ _UInt64Codes = Literal["uint64", "u8", "=u8", "<u8", ">u8"]
+
+ _Int8Codes = Literal["int8", "i1", "=i1", "<i1", ">i1"]
+ _Int16Codes = Literal["int16", "i2", "=i2", "<i2", ">i2"]
+ _Int32Codes = Literal["int32", "i4", "=i4", "<i4", ">i4"]
+ _Int64Codes = Literal["int64", "i8", "=i8", "<i8", ">i8"]
+
+ _Float16Codes = Literal["float16", "f2", "=f2", "<f2", ">f2"]
+ _Float32Codes = Literal["float32", "f4", "=f4", "<f4", ">f4"]
+ _Float64Codes = Literal["float64", "f8", "=f8", "<f8", ">f8"]
+
+ _Complex64Codes = Literal["complex64", "c8", "=c8", "<c8", ">c8"]
+ _Complex128Codes = Literal["complex128", "c16", "=c16", "<c16", ">c16"]
+
+ _ByteCodes = Literal["byte", "b", "=b", "<b", ">b"]
+ _ShortCodes = Literal["short", "h", "=h", "<h", ">h"]
+ _IntCCodes = Literal["intc", "i", "=i", "<i", ">i"]
+ _IntPCodes = Literal["intp", "int0", "p", "=p", "<p", ">p"]
+ _IntCodes = Literal["long", "int", "int_", "l", "=l", "<l", ">l"]
+ _LongLongCodes = Literal["longlong", "q", "=q", "<q", ">q"]
+
+ _UByteCodes = Literal["ubyte", "B", "=B", "<B", ">B"]
+ _UShortCodes = Literal["ushort", "H", "=H", "<H", ">H"]
+ _UIntCCodes = Literal["uintc", "I", "=I", "<I", ">I"]
+ _UIntPCodes = Literal["uintp", "uint0", "P", "=P", "<P", ">P"]
+ _UIntCodes = Literal["uint", "L", "=L", "<L", ">L"]
+ _ULongLongCodes = Literal["ulonglong", "Q", "=Q", "<Q", ">Q"]
+
+ _HalfCodes = Literal["half", "e", "=e", "<e", ">e"]
+ _SingleCodes = Literal["single", "f", "=f", "<f", ">f"]
+ _DoubleCodes = Literal["double" "float", "float_", "d", "=d", "<d", ">d"]
+ _LongDoubleCodes = Literal["longdouble", "longfloat", "g", "=g", "<g", ">g"]
+
+ _CSingleCodes = Literal["csingle", "singlecomplex", "F", "=F", "<F", ">F"]
+ _CDoubleCodes = Literal["cdouble" "complex", "complex_", "cfloat", "D", "=D", "<D", ">D"]
+ _CLongDoubleCodes = Literal["clongdouble", "clongfloat", "longcomplex", "G", "=G", "<G", ">G"]
+
+ _DT64Codes = Literal["datetime64", "M", "=M", "<M", ">M"]
+ _TD64Codes = Literal["timedelta64", "m", "=m", "<m", ">m"]
+
+ _StrCodes = Literal["str", "str_", "str0", "unicode", "unicode_", "U", "=U", "<U", ">U"]
+ _BytesCodes = Literal["bytes", "bytes_", "bytes0", "S", "=S", "<S", ">S"]
+ _VoidCodes = Literal["void", "void0", "V", "=V", "<V", ">V"]
+ _ObjectCodes = Literal["object", "object_", "O", "=O", "<O", ">O"]
+
+else:
+ _BoolCodes = Any
+
+ _UInt8Codes = Any
+ _UInt16Codes = Any
+ _UInt32Codes = Any
+ _UInt64Codes = Any
+
+ _Int8Codes = Any
+ _Int16Codes = Any
+ _Int32Codes = Any
+ _Int64Codes = Any
+
+ _Float16Codes = Any
+ _Float32Codes = Any
+ _Float64Codes = Any
+
+ _Complex64Codes = Any
+ _Complex128Codes = Any
+
+ _ByteCodes = Any
+ _ShortCodes = Any
+ _IntCCodes = Any
+ _IntPCodes = Any
+ _IntCodes = Any
+ _LongLongCodes = Any
+
+ _UByteCodes = Any
+ _UShortCodes = Any
+ _UIntCCodes = Any
+ _UIntPCodes = Any
+ _UIntCodes = Any
+ _ULongLongCodes = Any
+
+ _HalfCodes = Any
+ _SingleCodes = Any
+ _DoubleCodes = Any
+ _LongDoubleCodes = Any
+
+ _CSingleCodes = Any
+ _CDoubleCodes = Any
+ _CLongDoubleCodes = Any
+
+ _DT64Codes = Any
+ _TD64Codes = Any
+
+ _StrCodes = Any
+ _BytesCodes = Any
+ _VoidCodes = Any
+ _ObjectCodes = Any