Repository navigation
Make hash_class deterministic across processes and memoize it - #42
Merged
Merged
Conversation
hash_class used repr() on code constants and class variables, which embedded memory addresses and file paths (nested code objects, default object reprs) and hash-seed-dependent ordering (set/frozenset). Replace with a stable representation that recursively encodes nested code objects, sorts sets, and strips addresses. Also memoize results per class and algorithm using a WeakKeyDictionary. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
| Commit | Scanned at | New | Resolved | Net |
|---|---|---|---|---|
d772408 < |
2026-09-29 03:40 UTC | 0 | 0 | 0 |
Last scanned: d772408 · 2026-09-29 03:40 UTC
|
| Commit | Scanned at | New | Resolved | Net |
|---|---|---|---|---|
d772408 |
2026-09-29 03:40 UTC | — | — | — |
d772408 < |
2026-09-29 03:40 UTC | 0 | 0 | 0 |
Last scanned: d772408 · 2026-09-29 03:40 UTC
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
hash_classgave different results in different processes. It usedrepr()on code constants and class variables, which breaks in three ways:co_consts: theirreprincludes a memory address, the absolute file path and the line number.x in {"a", "b"}compiles to a frozenset):reprorder depends onPYTHONHASHSEED.at 0x....Changes
_stable_repr:module.qualname.reprwith memory addresses removed._extract_code_bytesinto_code_bytesso nested code can reuse it.WeakKeyDictionary, so classes created at runtime can still be garbage collected.Notes
_confingy_class_hashvalues in saved fingys will differ from the ones produced before this change. The hash is only used for the viz diff's "changed" markers.Test plan
PYTHONHASHSEEDvaluesmake pytest,make mypy,make lint,make format-checkpass🤖 Generated with Claude Code