Repository navigation
fix(version): set _hash_cache when copying a Version in _TrimmedRelease - #1242
Merged
Merged
Conversation
The fast path in `_TrimmedRelease.__init__` copied all Version slots from the source object except `_hash_cache`, leaving that slot uninitialized. Calling `hash()` on the resulting instance raised `AttributeError` because `Version.__hash__` reads the slot unconditionally. The fix copies `_hash_cache` unconditionally, mirroring `_key_cache`; every Version construction path initializes the slot, so it is always populated on the source object. Two regression tests cover both the fresh-Version and pre-hashed-Version cases. Assisted-by: ClaudeCode:claude-sonnet-4-6 Assisted-by: ClaudeCode:claude-fable-5
henryiii
force-pushed
the
fix/trimmed-release-hash-cache
branch
from
June 10, 2026 22:36
7d3841e to
9183e09
Compare
notatallshaw
approved these changes
Jul 8, 2026
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.
Looks like a simple missing line. Not likely to cause issues, but best for correctness.
🤖 AI text below 🤖
Part of #1239
Summary
_TrimmedRelease.__init__has a fast path (when given an existingVersionobject) that copies all internal state slots but omits
_hash_cache. Because__slots__leaves that slot uninitialized, callinghash()on the resultraises
AttributeError:Version.__hash__readsself._hash_cachedirectly (nogetattrguard),so any
_TrimmedReleasebuilt via the fast path was broken for hashing.Fix
Copy
_hash_cachefrom the source Version, wrapped intry/except AttributeErrorbecause the source's slot may itself be unset ifhash()was never called on it. Two regression tests cover both cases: a fresh
(never-hashed) source Version and a pre-hashed source Version.
🤖 Generated with Claude Code