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

Replace almost_equal_floats with math.isclose #7082

Merged
merged 1 commit into from Aug 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

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