inveniosoftware / inveniosoftware/dictdiffer

nested_hash fails on heterogeneous sets and dictionary keys

Open
#202 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
849
Forks
99
PR merge metrics
No merged PRs in 30d

Description

`nested_hash` sorts set members and dictionary items, which raises `TypeError` for ordinary heterogeneous containers. For example, on Python 3.12 and current master:

```python
from dictdiffer.utils import nested_hash
nested_hash({1, "one"})
nested_hash({1: ["one"], "two": {3, "three"}})
```

Both calls raise `TypeError: '<' not supported between instances of 'str' and 'int'`. These values are otherwise valid nested data, and this helper is also used by `Unifier`.

A regression should verify that both calls succeed and that changing dictionary insertion order does not change the resulting hash. I have a fix using order-independent hashing with regression tests; `run-tests.sh` passes locally.

Contributor guide

Open the contributing guide

Research direction

Start by locating the nested_hash helper and its regression tests, then inspect how Unifier uses it. Run run-tests.sh and verify that heterogeneous sets and dictionaries no longer raise TypeError and that changing dictionary insertion order does not change the resulting hash.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.