Skip to content

fix: dataclasses as dictionary keys#364

Merged
15r10nk merged 1 commit into
mainfrom
fix-dataclasses-as-dict-keys
Apr 23, 2026
Merged

fix: dataclasses as dictionary keys#364
15r10nk merged 1 commit into
mainfrom
fix-dataclasses-as-dict-keys

Conversation

@15r10nk

@15r10nk 15r10nk commented Apr 23, 2026

Copy link
Copy Markdown
Owner

Description

Related Issue(s)

closes #363

Checklist

  • I have tested my changes thoroughly (you can download the test coverage with hatch run cov:github).
  • I have added/updated relevant documentation.
  • I have added tests for new functionality (if applicable).
  • I have reviewed my own code for errors.
  • I have added a changelog entry with hatch run changelog:entry
  • I used semantic commits (feat: will cause a major and fix: a minor version bump)
  • You can squash you commits, otherwise they will be squashed during merge

@15r10nk 15r10nk force-pushed the fix-dataclasses-as-dict-keys branch 2 times, most recently from a2c89c8 to ba5bac4 Compare April 23, 2026 16:08
@15r10nk 15r10nk requested a review from Copilot April 23, 2026 16:15

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 use eq=False so they rely on Custom.__eq__/__hash__ (instead of dataclass-generated equality/hash), preventing key-collapsing in CustomDict.
  • Add a dedicated positional compare_CustomTuple implementation 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.

Comment thread src/inline_snapshot/_customize/_builder.py
Comment thread src/inline_snapshot/_new_adapter.py Outdated
Comment thread tests/adapter/test_sequence.py Outdated
Comment thread tests/adapter/test_sequence.py Outdated
Comment thread tests/adapter/test_sequence.py Outdated
Comment thread changelog.d/20260423_172841_15r10nk-git.md Outdated
@15r10nk 15r10nk force-pushed the fix-dataclasses-as-dict-keys branch from ba5bac4 to ae3b50e Compare April 23, 2026 16:32
@15r10nk 15r10nk merged commit b6d7d88 into main Apr 23, 2026
28 checks passed
@15r10nk 15r10nk deleted the fix-dataclasses-as-dict-keys branch May 27, 2026 19:33
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.

Snapshots of dicts don't work with dataclass keys

2 participants