Skip to content

Hash unordered containers without comparing their members - #204

Open
vitalivo wants to merge 1 commit into
inveniosoftware:masterfrom
vitalivo:fix/hash-unordered-heterogeneous-values
Open

vitalivo wants to merge 1 commit into
inveniosoftware:masterfrom
vitalivo:fix/hash-unordered-heterogeneous-values

Conversation

@vitalivo

Copy link
Copy Markdown

This replaces #203, which was accidentally closed and its source fork deleted. The implementation is unchanged; the original discussion and reviews remain linked there.


Fixes #202.

nested_hash sorts dictionary items and set members, which raises TypeError when their types cannot be ordered, such as 1 and 'one'. This also affects patch indexing in Unifier.

Use order-independent frozenset hashing for sets and dictionary key/value-hash pairs. Lists retain their ordered hashing behavior. Regression tests cover mixed set members, mixed dictionary keys, nested mutable values, and equivalent containers built in a different order.

Validation: both new tests raise TypeError before the fix. ./run-tests.sh passes on Python 3.12 with NumPy installed: 128 tests, 100% coverage, documentation build/doctests and pycodestyle. Pytest emits the existing warning about the unrecognized live_server_scope setting.

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.

nested_hash fails on heterogeneous sets and dictionary keys

1 participant