Author earwig
Recipients earwig
Date 2020-09-24.16:44:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1600965860.06.0.567784845074.issue41852@roundup.psfhosted.org>
In-reply-to
Content
json.dump vs. json.dumps have inconsistent error messages when encoding NaN with allow_nan=False:

>>> json.dumps(float('nan'), allow_nan=False)
ValueError: Out of range float values are not JSON compliant
>>> json.dump(float('nan'), sys.stdout, allow_nan=False)
ValueError: Out of range float values are not JSON compliant: nan

json.dump's error includes the value (which is useful); json.dumps's does not.

json.dumps uses this C implementation: https://github.com/python/cpython/blob/d67de0a30d76c6a28056bae22fd7d13f2e111b77/Modules/_json.c#L1340
json.dump uses this Python implementation: https://github.com/python/cpython/blob/d67de0a30d76c6a28056bae22fd7d13f2e111b77/Lib/json/encoder.py#L223

(Separately, is it expected that only one uses the C implementation? This seems it could have unexpected performance implications - without testing, I would've expected json.dump to take the "faster" path since it doesn't need to hold the entire encoded string in memory.)
History
Date User Action Args
2020-09-24 16:44:20earwigsetrecipients: + earwig
2020-09-24 16:44:20earwigsetmessageid: <1600965860.06.0.567784845074.issue41852@roundup.psfhosted.org>
2020-09-24 16:44:20earwiglinkissue41852 messages
2020-09-24 16:44:19earwigcreate