Skip to content

Commit f85bc18

Browse files
authored
🐛 fix color parsing when TypeError (#312)
1 parent 35102a4 commit f85bc18

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

Diff for: pydantic_extra_types/color.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ def parse_color_value(value: int | str, max_val: int = 255) -> float:
354354
"""
355355
try:
356356
color = float(value)
357-
except ValueError as e:
357+
except (ValueError, TypeError) as e:
358358
raise PydanticCustomError(
359359
'color_error',
360360
'value is not a valid color: color values must be a valid number',

Diff for: tests/test_types_color.py

+1
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ def test_color_success(raw_color, as_tuple):
9191
(0, 0, 1128, 0.5),
9292
(0, 0, 1128, -0.5),
9393
(0, 0, 1128, 1.5),
94+
({}, 0, 0),
9495
# rgb/rgba strings
9596
'rgb(0, 0, 1205)',
9697
'rgb(0, 0, 1128)',

0 commit comments

Comments
 (0)