_scalars.py 957 B

123456789101112131415161718192021222324252627282930
  1. from typing import Union, Tuple, Any
  2. import numpy as np
  3. # NOTE: `_StrLike_co` and `_BytesLike_co` are pointless, as `np.str_` and
  4. # `np.bytes_` are already subclasses of their builtin counterpart
  5. _CharLike_co = Union[str, bytes]
  6. # The 6 `<X>Like_co` type-aliases below represent all scalars that can be
  7. # coerced into `<X>` (with the casting rule `same_kind`)
  8. _BoolLike_co = Union[bool, np.bool_]
  9. _UIntLike_co = Union[_BoolLike_co, np.unsignedinteger]
  10. _IntLike_co = Union[_BoolLike_co, int, np.integer]
  11. _FloatLike_co = Union[_IntLike_co, float, np.floating]
  12. _ComplexLike_co = Union[_FloatLike_co, complex, np.complexfloating]
  13. _TD64Like_co = Union[_IntLike_co, np.timedelta64]
  14. _NumberLike_co = Union[int, float, complex, np.number, np.bool_]
  15. _ScalarLike_co = Union[
  16. int,
  17. float,
  18. complex,
  19. str,
  20. bytes,
  21. np.generic,
  22. ]
  23. # `_VoidLike_co` is technically not a scalar, but it's close enough
  24. _VoidLike_co = Union[Tuple[Any, ...], np.void]