Skip to content

Fix color parsing when TypeError #312

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion pydantic_extra_types/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def parse_color_value(value: int | str, max_val: int = 255) -> float:
"""
try:
color = float(value)
except ValueError as e:
except (ValueError, TypeError) as e:
raise PydanticCustomError(
'color_error',
'value is not a valid color: color values must be a valid number',
Expand Down
1 change: 1 addition & 0 deletions tests/test_types_color.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def test_color_success(raw_color, as_tuple):
(0, 0, 1128, 0.5),
(0, 0, 1128, -0.5),
(0, 0, 1128, 1.5),
({}, 0, 0),
# rgb/rgba strings
'rgb(0, 0, 1205)',
'rgb(0, 0, 1128)',
Expand Down