Skip to content

Commit 043358a

Browse files
gh-XXXXX: Fix pprint.isreadable() returning True for inf/nan
inf, -inf, nan are not valid Python literals so eval() fails on them. isreadable() should return False for these values.
1 parent 5944a53 commit 043358a

1 file changed

Lines changed: 4 additions & 0 deletions

File tree

Lib/pprint.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,10 @@ def _pprint_user_string(self, object, stream, indent, allowance, context, level)
626626
def _safe_repr(self, object, context, maxlevels, level):
627627
# Return triple (repr_string, isreadable, isrecursive).
628628
typ = type(object)
629+
if typ is float:
630+
import math
631+
if math.isinf(object) or math.isnan(object):
632+
return repr(object), False, False
629633
if typ in _builtin_scalars:
630634
return repr(object), True, False
631635

0 commit comments

Comments
 (0)