Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: use stdlib and remove useless code #86

Merged
merged 2 commits into from
Aug 20, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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