diff --git a/pydantic_extra_types/color.py b/pydantic_extra_types/color.py index d333acb..c40f794 100644 --- a/pydantic_extra_types/color.py +++ b/pydantic_extra_types/color.py @@ -15,7 +15,7 @@ from typing import Any, Callable, Tuple, Union, cast from pydantic import GetJsonSchemaHandler -from pydantic._internal import _repr, _utils +from pydantic._internal import _repr from pydantic.json_schema import JsonSchemaValue from pydantic_core import CoreSchema, PydanticCustomError, core_schema @@ -430,7 +430,7 @@ def parse_float_alpha(value: None | str | float | int) -> float | None: 'value is not a valid color: alpha values must be a valid float', ) - if _utils.almost_equal_floats(alpha, 1): + if math.isclose(alpha, 1): return None elif 0 <= alpha <= 1: return alpha @@ -479,11 +479,8 @@ def float_to_255(c: float) -> int: Returns: The integer equivalent of the given float value rounded to the nearest whole number. - - Raises: - ValueError: If the given float value is outside the acceptable range of 0 to 1 (inclusive). """ - return int(round(c * 255)) + return round(c * 255) COLORS_BY_NAME = {