Skip to content

Conversation

@bohdansolovie
Copy link

Summary

This PR adds comprehensive documentation to json_dumps() explaining why key sorting is critical for deterministic JSON output.

Motivation

The function had a TODO comment asking to document why key sorting is necessary. This is important because:

  • The JSON output is used to compute cache hashes (hash_digest/hash_digest_bytes in build.py)
  • Without sorted keys, dictionaries with identical content but different key insertion order produce different JSON strings
  • This leads to different hashes and incorrect cache invalidation in incremental type checking
  • The testIncrementalInternalScramble test specifically validates this behavior

Changes

  • Added detailed docstring explaining the relationship between JSON serialization and cache hashing
  • Removed TODO comment (now properly documented)
  • Removed redundant inline comment

Testing

No functional changes - this is documentation only. Existing tests should continue to pass.

bohdansolovie and others added 2 commits January 27, 2026 21:07
Add comprehensive docstring to json_dumps() explaining that key sorting
is critical for deterministic JSON output, which is used to compute
cache hashes in incremental type checking. Without sorted keys,
dictionaries with the same content but different key insertion order
would produce different hashes, causing incorrect cache invalidation.

This addresses the TODO comment and clarifies the relationship between
JSON serialization and the caching system.
@github-actions
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

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.

1 participant