Skip to content

gh-59091: Align pure-Python JSON container handling with C - #155080

Closed
Taeknology wants to merge 1 commit into
python:mainfrom
Taeknology:gh-59091-investigate
Closed

gh-59091: Align pure-Python JSON container handling with C#155080
Taeknology wants to merge 1 commit into
python:mainfrom
Taeknology:gh-59091-investigate

Conversation

@Taeknology

@Taeknology Taeknology commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Fixes #59091.

What changed

The pure-Python json encoder now uses an object's actual type hierarchy when dispatching list, tuple, dict, and frozendict values, matching the C accelerator. Objects that only spoof __class__ are routed through the encoder's default() handler instead of being treated as containers.

Genuine subclasses of the supported container types continue to be encoded normally.

Tests

Added shared pure-Python/C regression coverage for top-level and nested spoofed objects, plus genuine container subclasses. test_json.test_default and the full test_json suite pass locally.

Use actual type ancestry for list, tuple, dict, and frozendict dispatch
in the pure-Python encoder. This prevents objects that only spoof
__class__ from bypassing JSONEncoder.default(), while preserving real
container subclasses.
@picnixz

picnixz commented Aug 2, 2026

Copy link
Copy Markdown
Member

There was no prior discussion/update for the past 8y. We need to wonder whether the issue is still relevant and possibly decide on how to do it. So I am closing this premature PR. For longstanding issues, please wait for maintainers to confirm how relevant they are and the direction to take.

@picnixz picnixz closed this Aug 2, 2026
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.

json C vs pure-python implementation difference

2 participants