Skip to content

Handle dictionary keys that cannot be sorted in has_entries - #279

Open
ryanduguid wants to merge 1 commit into
hamcrest:mainfrom
ryanduguid:fix-unorderable-dictionary-keys
Open

ryanduguid wants to merge 1 commit into
hamcrest:mainfrom
ryanduguid:fix-unorderable-dictionary-keys

Conversation

@ryanduguid

Copy link
Copy Markdown

Summary

Allow has_entries to match dictionaries with mixed or unordered keys, including frozen dataclass instances. Preserve sorted descriptions and matcher evaluation order when sorting succeeds; use the original item order when comparisons raise TypeError.

items = list(value_matchers.items())
try:
    ordered_items = sorted(items)
except TypeError:
    ordered_items = items

Fixes #271. Add ten regression tests and a changelog fragment.

Evidence

  • Before: The initial regression run against the original runtime produces seven failing outcomes and 22 passes, including subtests. Mixed and frozen dataclass keys raise TypeError during construction.
    After: The focused suite passes all 27 tests. Coverage includes descriptions, first mismatch, evaluation order, input preservation, one-shot item iteration and exception boundaries.
  • Linux uv tool run tox -s: all 20 configured environments pass, including typing, lint, documentation, package description, changelog and coverage. CPython 3.10 through 3.14 each passes 456 tests with 14 NumPy skips, or 470 with NumPy. The four PyPy aliases each pass 448 tests with 15 skips and all resolve to PyPy 3.10.16.
  • Windows Python 3.14: 456 tests pass with 14 skips and two warnings; the configured lint target passes. Deliberate mutations that retry item acquisition, evaluate a second value after the first failure, or sort the fallback list in place fail the corresponding regression assertions.
  • Documentation builds successfully with 274 warnings. Coverage reports 98% for the changed runtime file and no partial branches.

Merge danger

Door: Two-way. Blast radius: Matcher consumers.

The fallback also absorbs TypeError raised by a custom comparison method. Errors from obtaining or materialising items, other comparison exceptions and value matcher exceptions still propagate. Fallback descriptions and the first mismatch follow the supplied item order.

Unverified

PyPy 3.11 and NumPy on PyPy were not exercised by the resolved local matrix. macOS, other Windows interpreters and the Windows typing/docs/package matrix were not run. Documentation warnings were not compared with the baseline. Only Python 3.14 has a full baseline suite comparison. Independent execution of the verification scripts, scanner version/parser coverage, hosted CI and maintainer acceptance remain unverified.

Keep the original item snapshot when sorting raises TypeError, while
preserving sorted order when comparisons succeed. Cover diagnostic and
evaluation order, one-shot items and exception boundaries, and add the
required changelog fragment for issue 271.
@ryanduguid
ryanduguid requested a deployment to publish-test-release October 8, 2026 10:12 — with GitHub Actions Waiting

This branch is waiting to be deployed

1 waiting deployment
publish-test-release — b3179388 Waiting Oct 8, 2026 by ryanduguid via Publish in-dev package to test.pypi.org #205
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.

has_entries TypeError if keys can't sort

1 participant