Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions Lib/json/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,11 @@ def default(self, o):
return JSONEncoder.default(self, o)

"""
if isinstance(o, float):
raise ValueError(
"Out of range float values are not JSON compliant: " +
repr(o)
)
raise TypeError(f'Object of type {o.__class__.__name__} '
f'is not JSON serializable')

Expand Down Expand Up @@ -236,9 +241,7 @@ def floatstr(o, allow_nan=self.allow_nan,
return _repr(o)

if not allow_nan:
raise ValueError(
"Out of range float values are not JSON compliant: " +
repr(o))
return self.default(o)

return text

Expand Down