_scalars.py 944 B

1234567891011121314151617181920
  1. from typing import Any, TypeAlias
  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: TypeAlias = str | bytes
  6. # The `<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: TypeAlias = bool | np.bool
  9. _UIntLike_co: TypeAlias = bool | np.unsignedinteger | np.bool
  10. _IntLike_co: TypeAlias = int | np.integer | np.bool
  11. _FloatLike_co: TypeAlias = float | np.floating | np.integer | np.bool
  12. _ComplexLike_co: TypeAlias = complex | np.number | np.bool
  13. _NumberLike_co: TypeAlias = _ComplexLike_co
  14. _TD64Like_co: TypeAlias = int | np.timedelta64 | np.integer | np.bool
  15. # `_VoidLike_co` is technically not a scalar, but it's close enough
  16. _VoidLike_co: TypeAlias = tuple[Any, ...] | np.void
  17. _ScalarLike_co: TypeAlias = complex | str | bytes | np.generic