diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index b15a4cfc7f7b..d1acef009e36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -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 diff --git a/doc/api/typing_api.rst b/doc/api/typing_api.rst index 16bf69d546af..ca11fecf81b7 100644 --- a/doc/api/typing_api.rst +++ b/doc/api/typing_api.rst @@ -2,6 +2,10 @@ ``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 @@ -9,3 +13,5 @@ .. autodata:: matplotlib.typing.MarkEveryType .. autodata:: matplotlib.typing.FillStyleType .. autodata:: matplotlib.typing.RcStyleType +.. autodata:: matplotlib.typing.HashableList + :annotation: Nested list with Hashable values diff --git a/lib/matplotlib/typing.py b/lib/matplotlib/typing.py index 6dcf82494020..d3237053a7bb 100644 --- a/lib/matplotlib/typing.py +++ b/lib/matplotlib/typing.py @@ -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]]] @@ -43,3 +57,4 @@ ] HashableList = list[Union[Hashable, "HashableList"]] +"""A nested list of Hashable values."""