Skip to content

Commit 7712714

Browse files
authored
Refactor: use stdlib and remove useless code (#86)
* Replace own code with stdlib's math.isclose * Remove useless int casting
1 parent e779d19 commit 7712714

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

pydantic_extra_types/color.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
from typing import Any, Callable, Tuple, Union, cast
1616

1717
from pydantic import GetJsonSchemaHandler
18-
from pydantic._internal import _repr, _utils
18+
from pydantic._internal import _repr
1919
from pydantic.json_schema import JsonSchemaValue
2020
from pydantic_core import CoreSchema, PydanticCustomError, core_schema
2121

@@ -430,7 +430,7 @@ def parse_float_alpha(value: None | str | float | int) -> float | None:
430430
'value is not a valid color: alpha values must be a valid float',
431431
)
432432

433-
if _utils.almost_equal_floats(alpha, 1):
433+
if math.isclose(alpha, 1):
434434
return None
435435
elif 0 <= alpha <= 1:
436436
return alpha
@@ -479,11 +479,8 @@ def float_to_255(c: float) -> int:
479479
480480
Returns:
481481
The integer equivalent of the given float value rounded to the nearest whole number.
482-
483-
Raises:
484-
ValueError: If the given float value is outside the acceptable range of 0 to 1 (inclusive).
485482
"""
486-
return int(round(c * 255))
483+
return round(c * 255)
487484

488485

489486
COLORS_BY_NAME = {

0 commit comments

Comments
 (0)