We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 3958418 commit 8c94ac3Copy full SHA for 8c94ac3
1 file changed
src/cachier/config.py
@@ -77,6 +77,18 @@ def _update_hash_for_value(hasher: "hashlib._Hash", value: Any) -> None:
77
_update_hash_for_value(hasher, value[dict_key])
78
return
79
80
+ if isinstance(value, (set, frozenset)):
81
+ # Use a deterministic ordering of elements for hashing.
82
+ hasher.update(b"frozenset" if isinstance(value, frozenset) else b"set")
83
+ try:
84
+ # Fast path: works for homogeneous, orderable element types.
85
+ iterable = sorted(value)
86
+ except TypeError:
87
+ # Fallback: impose a deterministic order based on type name and repr.
88
+ iterable = sorted(value, key=lambda item: (type(item).__name__, repr(item)))
89
+ for item in iterable:
90
+ _update_hash_for_value(hasher, item)
91
+ return
92
hasher.update(pickle.dumps(value, protocol=pickle.HIGHEST_PROTOCOL))
93
94
0 commit comments