Title: Inconsistent JSON serialization error messages · Issue #99925 · python/cpython · GitHub
Open Graph Title: Inconsistent JSON serialization error messages · Issue #99925 · python/cpython
X Title: Inconsistent JSON serialization error messages · Issue #99925 · python/cpython
Description: Bug report When you try to serialize a NaN, inf or -inf with json.dumps(..., allow_nan=False), the error messages are inconsistent, depending on whether you use the indent argument or not. >>> json.dumps(float('nan'), allow_nan=False) Va...
Open Graph Description: Bug report When you try to serialize a NaN, inf or -inf with json.dumps(..., allow_nan=False), the error messages are inconsistent, depending on whether you use the indent argument or not. >>> json...
X Description: Bug report When you try to serialize a NaN, inf or -inf with json.dumps(..., allow_nan=False), the error messages are inconsistent, depending on whether you use the indent argument or not. >>...
Opengraph URL: https://github.com/python/cpython/issues/99925
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent JSON serialization error messages","articleBody":"# Bug report\r\n\r\nWhen you try to serialize a `NaN`, `inf` or `-inf` with `json.dumps(..., allow_nan=False)`, the error messages are inconsistent, depending on whether you use the `indent` argument or not.\r\n\r\n```python\r\n\u003e\u003e\u003e json.dumps(float('nan'), allow_nan=False)\r\nValueError: Out of range float values are not JSON compliant\r\n\r\n\u003e\u003e\u003e json.dumps(float('nan'), allow_nan=False, indent=4)\r\nValueError: Out of range float values are not JSON compliant: nan\r\n```\r\n\r\nThat is because if you don't use `indent`, the encoding is done in C code [here](https://github.com/python/cpython/blob/0563be23a557917228a8b48cbb31bda285a3a815/Modules/_json.c#L1321-L1327),\r\nbut if you use `indent`, the encoding is done in pure Python code [here](https://github.com/python/cpython/blob/0563be23a557917228a8b48cbb31bda285a3a815/Lib/json/encoder.py#L239-L242), and the error messages are different between the two.\r\n\r\n# Your environment\r\n\r\n- CPython versions tested on: 3.11.0\r\n- Operating system and architecture: MacOS 12.6, Apple Silicon\n\n\u003c!-- gh-linked-prs --\u003e\n### Linked PRs\n* gh-99926\n\u003c!-- /gh-linked-prs --\u003e\n","author":{"url":"https://github.com/fnesveda","@type":"Person","name":"fnesveda"},"datePublished":"2022-12-01T14:25:23.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/99925/cpython/issues/99925"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:2b3472e8-c80e-ea70-431b-1f45783c9c89 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | DA24:2D44C5:262210F:35BBDBB:69691BD4 |
| html-safe-nonce | 5870159cd57b9c672924a9bfea8ad7af07c34fa4eefcf05ae8b0fa4f717a2264 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEQTI0OjJENDRDNToyNjIyMTBGOjM1QkJEQkI6Njk2OTFCRDQiLCJ2aXNpdG9yX2lkIjoiMjI0MTI0OTU4OTA2ODM3Mjk0OCIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | 6a2700a353ad53770a6f348e672106ad76c0981497479ba5d133bafc53689cbe |
| hovercard-subject-tag | issue:1471410552 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/99925/issue_layout |
| twitter:image | https://opengraph.githubassets.com/2ac9ea8e6e1b989ee629581a44a8cc2245396fd224708e9e0cef17f1fced37e5/python/cpython/issues/99925 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/2ac9ea8e6e1b989ee629581a44a8cc2245396fd224708e9e0cef17f1fced37e5/python/cpython/issues/99925 |
| og:image:alt | Bug report When you try to serialize a NaN, inf or -inf with json.dumps(..., allow_nan=False), the error messages are inconsistent, depending on whether you use the indent argument or not. >>> json... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | fnesveda |
| hostname | github.com |
| expected-hostname | github.com |
| None | 0e60568924309a021b51adabdce15c2a2f285b556f3130d1a2fa2a5bce11c55f |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | dd206f7ed6207863172be4a783826e86bd2375c3 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width