Skip to content

Commit 791bdfa

Browse files
committed
fixing the implementation for hashing uuid
1 parent 66eb8f6 commit 791bdfa

File tree

3 files changed

+4
-11
lines changed

3 files changed

+4
-11
lines changed

deepdiff/deephash.py

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,7 @@ def _prep_number(self, obj):
488488
number_format_notation=self.number_format_notation)
489489
return KEY_TO_VAL_STR.format(type_, obj)
490490

491-
def _prep_ipranges(self, obj):
491+
def _prep_ipranges(self, obj) -> str:
492492
type_ = 'iprange'
493493
obj = str(obj)
494494
return KEY_TO_VAL_STR.format(type_, obj)
@@ -572,14 +572,7 @@ def _hash(self, obj, parent, parents_ids=EMPTY_FROZENSET):
572572

573573
elif isinstance(obj, uuid.UUID):
574574
# Handle UUID objects (including uuid6.UUID) by using their integer value
575-
result = f"uuid:{obj.int}"
576-
if self.apply_hash:
577-
result = self.hasher(result)
578-
try:
579-
self.hashes[obj] = (result, counts)
580-
except TypeError:
581-
self.hashes[get_id(obj)] = (result, counts)
582-
return result, counts
575+
result = str(obj)
583576

584577
elif isinstance(obj, MutableMapping):
585578
result, counts = self._prep_dict(obj=obj, parent=parent, parents_ids=parents_ids)

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ dev = [
5555
"pandas~=2.2.0",
5656
"polars~=1.21.0",
5757
"nox==2025.5.1",
58+
"uuid6==2025.0.1",
5859
]
5960
docs = [
6061
# We use the html style that is not supported in Sphinx 7 anymore.

tests/test_hash.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import pytest
44
import pytz
5+
import uuid6
56
import logging
67
import datetime
78
import ipaddress
@@ -210,7 +211,6 @@ def test_numpy_datetime64(self):
210211

211212
def test_uuid6_hash_positive(self):
212213
"""Positive test case: Same UUID objects should produce the same hash."""
213-
import uuid6
214214
uuid_obj = uuid6.uuid7()
215215
hash1 = DeepHash(uuid_obj)
216216
hash2 = DeepHash(uuid_obj)
@@ -223,7 +223,6 @@ def test_uuid6_hash_positive(self):
223223

224224
def test_uuid6_deepdiff_negative(self):
225225
"""Negative test case: DeepDiff should detect differences between sets containing different UUID objects."""
226-
import uuid6
227226
dummy_id_1 = uuid6.uuid7()
228227
dummy_id_2 = uuid6.uuid7()
229228
set1 = {dummy_id_1}

0 commit comments

Comments
 (0)