Skip to content

Commit

Permalink
Replace almost_equal_floats with math.isclose (#7082)
Browse files Browse the repository at this point in the history
  • Loading branch information
eumiro committed Aug 10, 2023
1 parent 998a6ba commit 84a8014
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 7 deletions.
5 changes: 0 additions & 5 deletions pydantic/_internal/_utils.py
Expand Up @@ -114,11 +114,6 @@ def update_not_none(mapping: dict[Any, Any], **update: Any) -> None:
mapping.update({k: v for k, v in update.items() if v is not None})


def almost_equal_floats(value_1: float, value_2: float, *, delta: float = 1e-8) -> bool:
"""Return True if two floats are almost equal."""
return abs(value_1 - value_2) <= delta


T = TypeVar('T')


Expand Down
4 changes: 2 additions & 2 deletions pydantic/color.py
Expand Up @@ -19,7 +19,7 @@
from pydantic_core import CoreSchema, PydanticCustomError, core_schema
from typing_extensions import deprecated

from ._internal import _repr, _utils
from ._internal import _repr
from ._internal._schema_generation_shared import GetJsonSchemaHandler as _GetJsonSchemaHandler
from .json_schema import JsonSchemaValue
from .warnings import PydanticDeprecatedSince20
Expand Down Expand Up @@ -399,7 +399,7 @@ def parse_float_alpha(value: Union[None, str, float, int]) -> Optional[float]:
except ValueError:
raise PydanticCustomError('color_error', '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

0 comments on commit 84a8014

Please sign in to comment.