Issue
isreadable is documented as returning True if the object's repr is readable by the interpreter — implying eval(pformat(obj)) == obj. For float and complex non-finite values, isreadable returns True, but the roundtrip fails — eval raises NameError since inf and nan aren't valid Python expressions.
Reproducer
import pprint
print(pprint.isreadable(float('inf'))) # True — but eval('inf') raises NameError
print(pprint.isreadable(float('nan'))) # True
print(pprint.isreadable(complex(float('inf'), 0))) # True
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs
Issue
isreadableis documented as returningTrueif the object's repr is readable by the interpreter — implyingeval(pformat(obj)) == obj. For float and complex non-finite values,isreadablereturnsTrue, but the roundtrip fails —evalraisesNameErrorsinceinfandnanaren't valid Python expressions.Reproducer
CPython versions tested on:
CPython main branch
Operating systems tested on:
No response
Linked PRs