typing.py 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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, Callable, Literal, TypeAlias, TypeVar, Union
  12. from . import path
  13. from ._enums import JoinStyle, CapStyle
  14. from .artist import Artist
  15. from .backend_bases import RendererBase
  16. from .markers import MarkerStyle
  17. from .transforms import Bbox, Transform
  18. RGBColorType: TypeAlias = tuple[float, float, float] | str
  19. RGBAColorType: TypeAlias = (
  20. str | # "none" or "#RRGGBBAA"/"#RGBA" hex strings
  21. tuple[float, float, float, float] |
  22. # 2 tuple (color, alpha) representations, not infinitely recursive
  23. # RGBColorType includes the (str, float) tuple, even for RGBA strings
  24. tuple[RGBColorType, float] |
  25. # (4-tuple, float) is odd, but accepted as the outer float overriding A of 4-tuple
  26. tuple[tuple[float, float, float, float], float]
  27. )
  28. ColorType: TypeAlias = RGBColorType | RGBAColorType
  29. RGBColourType: TypeAlias = RGBColorType
  30. RGBAColourType: TypeAlias = RGBAColorType
  31. ColourType: TypeAlias = ColorType
  32. LineStyleType: TypeAlias = str | tuple[float, Sequence[float]]
  33. DrawStyleType: TypeAlias = Literal["default", "steps", "steps-pre", "steps-mid",
  34. "steps-post"]
  35. MarkEveryType: TypeAlias = (
  36. None |
  37. int | tuple[int, int] | slice | list[int] |
  38. float | tuple[float, float] |
  39. list[bool]
  40. )
  41. MarkerType: TypeAlias = str | path.Path | MarkerStyle
  42. FillStyleType: TypeAlias = Literal["full", "left", "right", "bottom", "top", "none"]
  43. JoinStyleType: TypeAlias = JoinStyle | Literal["miter", "round", "bevel"]
  44. CapStyleType: TypeAlias = CapStyle | Literal["butt", "projecting", "round"]
  45. CoordsBaseType = Union[
  46. str,
  47. Artist,
  48. Transform,
  49. Callable[
  50. [RendererBase],
  51. Union[Bbox, Transform]
  52. ]
  53. ]
  54. CoordsType = Union[
  55. CoordsBaseType,
  56. tuple[CoordsBaseType, CoordsBaseType]
  57. ]
  58. RcStyleType: TypeAlias = (
  59. str |
  60. dict[str, Any] |
  61. pathlib.Path |
  62. Sequence[str | pathlib.Path | dict[str, Any]]
  63. )
  64. _HT = TypeVar("_HT", bound=Hashable)
  65. HashableList: TypeAlias = list[_HT | "HashableList[_HT]"]
  66. """A nested list of Hashable values."""