Skip to content

gh-134717: Allow overriding serialization of NaN and Infinity in json.encoder#134715

Open
krzyszti wants to merge 3 commits into
python:mainfrom
krzyszti:patch-1
Open

gh-134717: Allow overriding serialization of NaN and Infinity in json.encoder#134715
krzyszti wants to merge 3 commits into
python:mainfrom
krzyszti:patch-1

Conversation

@krzyszti

@krzyszti krzyszti commented May 26, 2025

Copy link
Copy Markdown

This change modifies the json.encoder module to permit customization of how special floating-point values (NaN, Infinity, -Infinity) are serialized. By introducing a floatstr function, developers can now define alternative representations for these values, such as null, 0, or custom strings, enhancing flexibility in JSON output.

This change can allow the programmer to override Nan/Infinity/-Infinity to be not only NaN but null, 0 or whatever they want it to be.
@python-cla-bot

python-cla-bot Bot commented May 26, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented May 26, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@krzyszti krzyszti changed the title gh-112517: Allow overriding serialization of NaN and Infinity in json.encoder gh-134717: Allow overriding serialization of NaN and Infinity in json.encoder May 26, 2025
@bedevere-app

bedevere-app Bot commented May 26, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app

bedevere-app Bot commented May 26, 2025

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@sharktide sharktide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krzyszti
The news entry here is in the wrong place and format. Please move it to /next/Library/ and use blurb or blurb it to create the entry. The content {of the news entry} looks fine though

@sharktide sharktide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self isn't defined here either

@nineteendo

Copy link
Copy Markdown
Contributor

Also keep in mind that the C implementation will still be called if you override floatstr.

@github-actions

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting core review stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants