Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Inconsistent JSON serialization error messages #99925

Copy link
Copy link
Closed
@fnesveda

Description

@fnesveda
Issue body actions

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)
ValueError: Out of range float values are not JSON compliant

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

That is because if you don't use indent, the encoding is done in C code here,
but if you use indent, the encoding is done in pure Python code here, and the error messages are different between the two.

Your environment

  • CPython versions tested on: 3.11.0
  • Operating system and architecture: MacOS 12.6, Apple Silicon

Linked PRs

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error

    Projects

    Status

    Done
    Show more project fields

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.