typing.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. """
  2. Typing support for Matplotlib
  3. This module contains Type aliases which are useful for Matplotlib and potentially
  4. downstream libraries.
  5. .. admonition:: Provisional status of typing
  6. The ``typing`` module and type stub files are considered provisional and may change
  7. at any time without a deprecation period.
  8. """
  9. from collections.abc import Hashable, Sequence
  10. import pathlib
  11. from typing import Any, Literal, TypeVar, Union
  12. from . import path
  13. from ._enums import JoinStyle, CapStyle
  14. from .markers import MarkerStyle
  15. # The following are type aliases. Once python 3.9 is dropped, they should be annotated
  16. # using ``typing.TypeAlias`` and Unions should be converted to using ``|`` syntax.
  17. RGBColorType = Union[tuple[float, float, float], str]
  18. RGBAColorType = Union[
  19. str, # "none" or "#RRGGBBAA"/"#RGBA" hex strings
  20. tuple[float, float, float, float],
  21. # 2 tuple (color, alpha) representations, not infinitely recursive
  22. # RGBColorType includes the (str, float) tuple, even for RGBA strings
  23. tuple[RGBColorType, float],
  24. # (4-tuple, float) is odd, but accepted as the outer float overriding A of 4-tuple
  25. tuple[tuple[float, float, float, float], float],
  26. ]
  27. ColorType = Union[RGBColorType, RGBAColorType]
  28. RGBColourType = RGBColorType
  29. RGBAColourType = RGBAColorType
  30. ColourType = ColorType
  31. LineStyleType = Union[str, tuple[float, Sequence[float]]]
  32. DrawStyleType = Literal["default", "steps", "steps-pre", "steps-mid", "steps-post"]
  33. MarkEveryType = Union[
  34. None, int, tuple[int, int], slice, list[int], float, tuple[float, float], list[bool]
  35. ]
  36. MarkerType = Union[str, path.Path, MarkerStyle]
  37. FillStyleType = Literal["full", "left", "right", "bottom", "top", "none"]
  38. JoinStyleType = Union[JoinStyle, Literal["miter", "round", "bevel"]]
  39. CapStyleType = Union[CapStyle, Literal["butt", "projecting", "round"]]
  40. RcStyleType = Union[
  41. str,
  42. dict[str, Any],
  43. pathlib.Path,
  44. Sequence[Union[str, pathlib.Path, dict[str, Any]]],
  45. ]
  46. _HT = TypeVar("_HT", bound=Hashable)
  47. HashableList = list[Union[_HT, "HashableList[_HT]"]]
  48. """A nested list of Hashable values."""