Skip to content
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Whitespace
  • Loading branch information
landoskape committed Jan 4, 2025
commit c3cf8d41dd8ac52d2ec6f2f2588ed3c21518231e
6 changes: 5 additions & 1 deletion lib/matplotlib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,10 @@ def _has_alpha_channel(c):

If *c* is not a valid color specifier, then the result is undefined.
"""
# If c isn't a color, this is undefined. Return False instead of raising.
if not is_color_like(c):
return False

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One should probably check the code if this has already been called. Since this is a private method one can require that it is checked.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I'm sure I know how to do that or what you mean. Would you explain a little more?

(also, thanks for the comments, as always)

Comment thread
landoskape marked this conversation as resolved.
Outdated

# if c is a hex, it has an alpha channel when it has 4 (or 8) digits after '#'
if isinstance(c, str):
if c[0] == '#' and (len(c) == 5 or len(c) == 9):
Expand All @@ -251,7 +255,7 @@ def _has_alpha_channel(c):

# if it has length 2, it's a color/alpha tuple
# if the second element isn't None or the first element has length = 4
if len(c) == 2 and (c[1] is not None or _has_alpha_channel(c[0]):
if len(c) == 2 and (c[1] is not None or _has_alpha_channel(c[0])):
# example: ([0.5, 0.5, 0.5, 0.5], None) or ('r', 0.5)
return True

Expand Down