Skip to content

Commit

Permalink
Refactor: use stdlib and remove useless code (#86)
Browse files Browse the repository at this point in the history
* Replace own code with stdlib's math.isclose

* Remove useless int casting
  • Loading branch information
eumiro committed Aug 20, 2023
1 parent e779d19 commit 7712714
Showing 1 changed file with 3 additions and 6 deletions.
9 changes: 3 additions & 6 deletions pydantic_extra_types/color.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 = {
Expand Down

0 comments on commit 7712714

Please sign in to comment.