Fixed _has_alpha_channel function to work with hex and tuple colors #27463
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PR summary
This PR fixes bug #27321. The _has_alpha_channel function didn't work for hex strings and tuples because it just checked for decimal strings of length 4 (RGBA). The new implementation cases on the three different possible inputs (decimal, hex, and tuple) and determines if the input is a valid color that has an alpha channel. For checking hex colors, the function checks if all the symbols are hex values (0-9, A-F), and if the string is the correct length. Since hex values can be represented with the prefix "#" or "0x", the input strings have to be of length 9 or 10 (prefix + 4 bytes or 8 hex values for all channels).
PR checklist
Note
This PR doesn't pass the MyPy Stubtest, but passes all of the others. I'm not entirely sure how to get it to pass that, although it doesn't seem like too big of an error.