From f43fd7cf4fde68965ab7e36f414f5989948cda0a Mon Sep 17 00:00:00 2001 From: ilias Date: Fri, 18 Apr 2025 11:01:04 +0300 Subject: [PATCH] :bug: fix color parsing when TypeError (#311) --- pydantic_extra_types/color.py | 2 +- tests/test_types_color.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/pydantic_extra_types/color.py b/pydantic_extra_types/color.py index 92995e50..18d96333 100644 --- a/pydantic_extra_types/color.py +++ b/pydantic_extra_types/color.py @@ -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', diff --git a/tests/test_types_color.py b/tests/test_types_color.py index defec19d..8e88ef6a 100644 --- a/tests/test_types_color.py +++ b/tests/test_types_color.py @@ -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)',