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

Skip to content

Commit ddb3163

Browse files
authored
Merge pull request matplotlib#25597 from ksunden/colortype
Add (color, alpha) tuple as a valid ColorType in typing.py
2 parents cc72116 + 77f6919 commit ddb3163

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,6 +2,10 @@
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
@@ -11,3 +15,5 @@
1115
.. autodata:: matplotlib.typing.CapStyleType
1216
.. autodata:: matplotlib.typing.JoinStyleType
1317
.. autodata:: matplotlib.typing.RcStyleType
18+
.. autodata:: matplotlib.typing.HashableList
19+
:annotation: Nested list with Hashable values

lib/matplotlib/typing.py

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

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

2640
LineStyleType = Union[str, tuple[float, Sequence[float]]]
@@ -46,3 +60,4 @@
4660
]
4761

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

0 commit comments

Comments
 (0)