Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5ee8a74

Browse files
committed
Add (color, alpha) tuple as a valid ColorType
Introduced by #24691, merged shortly before #24976 Noticed that one of the other type aliases was not documented, so fixed that while I was editing these two files
1 parent a844eca commit 5ee8a74

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ repos:
1717
hooks:
1818
- id: check-added-large-files
1919
- id: check-docstring-first
20+
exclude: lib/matplotlib/typing.py # docstring used for attribute flagged by check
2021
- id: end-of-file-fixer
2122
exclude_types: [svg]
2223
- id: mixed-line-ending

doc/api/typing_api.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
``matplotlib.typing``
33
*********************
44

5+
.. autodata:: matplotlib.typing.RGBColorType
6+
.. autodata:: matplotlib.typing.RGBColourType
7+
.. autodata:: matplotlib.typing.RGBAColorType
8+
.. autodata:: matplotlib.typing.RGBAColourType
59
.. autodata:: matplotlib.typing.ColorType
610
.. autodata:: matplotlib.typing.ColourType
711
.. autodata:: matplotlib.typing.LineStyleType
812
.. autodata:: matplotlib.typing.DrawStyleType
913
.. autodata:: matplotlib.typing.MarkEveryType
1014
.. autodata:: matplotlib.typing.FillStyleType
1115
.. autodata:: matplotlib.typing.RcStyleType
16+
.. autodata:: matplotlib.typing.HashableList
17+
:annotation: Nested list with Hashable values

lib/matplotlib/typing.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,21 @@
1919
# The following are type aliases. Once python 3.9 is dropped, they should be annotated
2020
# using ``typing.TypeAlias`` and Unions should be converted to using ``|`` syntax.
2121

22-
ColorType = Union[tuple[float, float, float], tuple[float, float, float, float], str]
22+
RGBColorType = Union[tuple[float, float, float], tuple[float, float, float, float], str]
23+
RGBAColorType = Union[
24+
str, # "none" or "#RRGGBBAA"/"#RGBA" hex strings
25+
tuple[float, float, float, float],
26+
# 2 tuple (color, alpha) representations, not infinitely recursive
27+
# RGBColorType includes the (str, float) tuple, even for RGBA strings
28+
tuple[RGBColorType, float],
29+
# (4-tuple, float) is odd, but accepted as the outer float overriding A of 4-tuple
30+
tuple[tuple[float, float, float, float], float]
31+
]
32+
33+
ColorType = Union[RGBColorType, RGBAColorType]
34+
35+
RGBColourType = RGBColorType
36+
RGBAColourType = RGBAColorType
2337
ColourType = ColorType
2438

2539
LineStyleType = Union[str, tuple[float, Sequence[float]]]
@@ -43,3 +57,4 @@
4357
]
4458

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

0 commit comments

Comments
 (0)