Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ repos:
hooks:
- id: check-added-large-files
- id: check-docstring-first
exclude: lib/matplotlib/typing.py # docstring used for attribute flagged by check
- id: end-of-file-fixer
exclude_types: [svg]
- id: mixed-line-ending
Expand Down
6 changes: 6 additions & 0 deletions doc/api/typing_api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
``matplotlib.typing``
*********************

.. autodata:: matplotlib.typing.RGBColorType
.. autodata:: matplotlib.typing.RGBColourType
.. autodata:: matplotlib.typing.RGBAColorType
.. autodata:: matplotlib.typing.RGBAColourType
.. autodata:: matplotlib.typing.ColorType
.. autodata:: matplotlib.typing.ColourType
.. autodata:: matplotlib.typing.LineStyleType
.. autodata:: matplotlib.typing.DrawStyleType
.. autodata:: matplotlib.typing.MarkEveryType
.. autodata:: matplotlib.typing.FillStyleType
.. autodata:: matplotlib.typing.RcStyleType
.. autodata:: matplotlib.typing.HashableList
:annotation: Nested list with Hashable values
17 changes: 16 additions & 1 deletion lib/matplotlib/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,21 @@
# The following are type aliases. Once python 3.9 is dropped, they should be annotated
# using ``typing.TypeAlias`` and Unions should be converted to using ``|`` syntax.

ColorType = Union[tuple[float, float, float], tuple[float, float, float, float], str]
RGBColorType = Union[tuple[float, float, float], str]
RGBAColorType = Union[
str, # "none" or "#RRGGBBAA"/"#RGBA" hex strings
tuple[float, float, float, float],
# 2 tuple (color, alpha) representations, not infinitely recursive
# RGBColorType includes the (str, float) tuple, even for RGBA strings
tuple[RGBColorType, float],
# (4-tuple, float) is odd, but accepted as the outer float overriding A of 4-tuple
tuple[tuple[float, float, float, float], float]
]

ColorType = Union[RGBColorType, RGBAColorType]

RGBColourType = RGBColorType
RGBAColourType = RGBAColorType
ColourType = ColorType

LineStyleType = Union[str, tuple[float, Sequence[float]]]
Expand All @@ -43,3 +57,4 @@
]

HashableList = list[Union[Hashable, "HashableList"]]
"""A nested list of Hashable values."""