fix: dataclasses as dictionary keys#364
Merged
Merged
Conversation
a2c89c8 to
ba5bac4
Compare
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes snapshot corruption when dictionaries use dataclass instances (and similar “call-represented” objects) as keys by ensuring Custom* wrapper objects don’t accidentally collapse as dict keys. It also adjusts tuple fixing to be positional (rather than alignment-based) so expressions are preserved more predictably when tuples grow/shrink.
Changes:
- Make multiple
Custom*dataclasses useeq=Falseso they rely onCustom.__eq__/__hash__(instead of dataclass-generated equality/hash), preventing key-collapsing inCustomDict. - Add a dedicated positional
compare_CustomTupleimplementation and expand tuple-related adapter tests. - Add a regression test for dataclasses as dict keys and update CI + changelog fragment.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
src/inline_snapshot/_customize/_custom_call.py |
Prevent dataclass-generated equality/hash on CustomCall/CustomDefault (critical for dict-key behavior). |
src/inline_snapshot/_customize/_custom_dict.py |
Prevent CustomDict from getting dataclass equality/hash that can cause collisions. |
src/inline_snapshot/_customize/_custom_external.py |
Align CustomExternal equality/hash behavior with Custom base class. |
src/inline_snapshot/_customize/_custom_unmanaged.py |
Align CustomUnmanaged equality behavior with Custom base class. |
src/inline_snapshot/_customize/_builder.py |
Add a guard to detect key-collapsing during create_dict(). |
src/inline_snapshot/_new_adapter.py |
Split tuple comparison into a dedicated positional implementation. |
tests/adapter/test_dataclass.py |
Regression test for dict snapshots with dataclass keys (issue #363). |
tests/adapter/test_sequence.py |
Add new tuple fix/update tests for the adapter behavior. |
tests/test_preserve_values.py |
Update expectations and reduce generic brace coverage to exclude tuples. |
changelog.d/20260423_172841_15r10nk-git.md |
Add changelog entry for the fixes. |
.github/workflows/ci.yml |
Update CI matrix to use pypy3.11 instead of older PyPy versions. |
ba5bac4 to
ae3b50e
Compare
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.
Description
Related Issue(s)
closes #363
Checklist
hatch run cov:github).hatch run changelog:entryfeat:will cause a major andfix:a minor version bump)