Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix json.dump/dumps() with IPv4Address #9769

Closed
wants to merge 1 commit into from

Conversation

romkey
Copy link

@romkey romkey commented Oct 28, 2024

Change ipaddress_ipv4address_print() to quote the IPv4Address if kind is PRINT_JSON

Fixes issue 9768

Without fix:
Screenshot 2024-10-28 at 11 12 40 AM
With fix:
Screenshot 2024-10-28 at 11 19 32 AM

Copy link
Collaborator

@dhalbert dhalbert left a comment

Choose a reason for hiding this comment

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

See #9768 (comment). We want to be compatible with CPython, which will not produce valid JSON with an ipaddress.IPv4Address object either. But instead we should print the address as IPv4Address(...), and similarly for IPv6Address.

@jepler
Copy link
Member

jepler commented Nov 2, 2024

This issue has been reported upstream at Micropython with the response that "This was a design decision. It's undefined behaviour if you serialise something that can't be serialised" micropython#1719

@jepler
Copy link
Member

jepler commented Nov 2, 2024

And documented in Micropython. we may not be reproducing this portion of the documentation in the circuitpython online docs. https://docs.micropython.org/en/latest/genrst/modules.html#json-module-does-not-throw-exception-when-object-is-not-serialisable

@romkey romkey closed this Nov 4, 2024
@romkey romkey deleted the json-dump-ipaddress branch November 4, 2024 16:47
@dhalbert
Copy link
Collaborator

dhalbert commented Nov 4, 2024

This is subsumed by #9789.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Invalid output from json.dump/dumps with IPV4Address
3 participants