8000 fix float nan comparison · rpgod/python-betterproto@6f7d706 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f7d706

Browse files
authored
fix float nan comparison
This change also adds minor docstrings fixes and bumps pre-commit blac version.
1 parent ac96d82 commit 6f7d706

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

src/betterproto/__init__.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ def _parse_float(value: Any) -> float:
434434
435435
Parameters
436436
----------
437-
value : Any
437+
value: Any
438438
Value to parse
439439
440440
Returns
@@ -456,20 +456,19 @@ def _dump_float(value: float) -> Union[float, str]:
456456
457457
Parameters
458458
----------
459-
value : float
459+
value: float
460460
Value to dump
461461
462462
Returns
463463
-------
464464
Union[float, str]
465-
Dumped valid, either a float or the strings
466-
"Infinity" or "-Infinity"
465+
Dumped value, either a float or the strings
467466
"""
468467
if value == float("inf"):
469468
return INFINITY
470469
if value == -float("inf"):
471470
return NEG_INFINITY
472-
if value == float("nan"):
471+
if isinstance(value, float) and math.isnan(value):
473472
return NAN
474473
return value
475474

0 commit comments

Comments
 (0)
0