Skip to content

Return None instead of crashing on an invalid alpha in color5 - #82

Closed
RavSinghChandan wants to merge 1 commit into
Kozea:mainfrom
RavSinghChandan:color5-invalid-alpha
Closed

RavSinghChandan wants to merge 1 commit into
Kozea:mainfrom
RavSinghChandan:color5-invalid-alpha

Conversation

@RavSinghChandan

Copy link
Copy Markdown

color5.parse_color() is documented to return None for an invalid color without raising, but an invalid alpha in device-cmyk() or in a custom color space crashes:

>>> color5.parse_color('device-cmyk(0 0 0 0 / foo)')
TypeError: float() argument must be a string or a real number, not 'NoneType'
>>> color5.parse_color('color(--custom 1 0 0 / foo)')
TypeError: ...

color4._parse_alpha() returns None for an invalid alpha, which color4.parse_color() checks but color5 passed straight to Color(). It is now checked the same way, so these colors give None. Valid alphas and every other color are unchanged.

Added test_color_invalid_alpha_5; all three cases raise TypeError before the fix

@grewn0uille

Copy link
Copy Markdown
Member

There are guidelines for contributions. Please follow them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants