From 6f7d706a8ef8dcc7fb9a7f4325e629a90ef0d86f Mon Sep 17 00:00:00 2001 From: James Hilton-Balfe Date: Sun, 24 Apr 2022 00:13:58 +0100 Subject: [PATCH] fix float nan comparison This change also adds minor docstrings fixes and bumps pre-commit blac version. --- src/betterproto/__init__.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/src/betterproto/__init__.py b/src/betterproto/__init__.py index 0e6651380..0dcf1e5cb 100644 --- a/src/betterproto/__init__.py +++ b/src/betterproto/__init__.py @@ -434,7 +434,7 @@ def _parse_float(value: Any) -> float: Parameters ---------- - value : Any + value: Any Value to parse Returns @@ -456,20 +456,19 @@ def _dump_float(value: float) -> Union[float, str]: Parameters ---------- - value : float + value: float Value to dump Returns ------- Union[float, str] - Dumped valid, either a float or the strings - "Infinity" or "-Infinity" + Dumped value, either a float or the strings """ if value == float("inf"): return INFINITY if value == -float("inf"): return NEG_INFINITY - if value == float("nan"): + if isinstance(value, float) and math.isnan(value): return NAN return value