Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
default_language_version:
python: python3.8
python: python3

ci:
autofix_prs: true
Expand Down
17 changes: 15 additions & 2 deletions monai/data/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import math
import os
import pickle
import sys
from collections import abc, defaultdict
from collections.abc import Generator, Iterable, Mapping, Sequence, Sized
from copy import deepcopy
Expand Down Expand Up @@ -1370,7 +1371,13 @@ def json_hashing(item) -> bytes:

"""
# TODO: Find way to hash transforms content as part of the cache
cache_key = hashlib.md5(json.dumps(item, sort_keys=True).encode("utf-8")).hexdigest()
cache_key = ""
if sys.version_info.minor < 9:
cache_key = hashlib.md5(json.dumps(item, sort_keys=True).encode("utf-8")).hexdigest()
else:
cache_key = hashlib.md5(
json.dumps(item, sort_keys=True).encode("utf-8"), usedforsecurity=False # type: ignore
).hexdigest()
return f"{cache_key}".encode()


Expand All @@ -1385,7 +1392,13 @@ def pickle_hashing(item, protocol=pickle.HIGHEST_PROTOCOL) -> bytes:
Returns: the corresponding hash key

"""
cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol)).hexdigest()
cache_key = ""
if sys.version_info.minor < 9:
cache_key = hashlib.md5(pickle.dumps(sorted_dict(item), protocol=protocol)).hexdigest()
else:
cache_key = hashlib.md5(
pickle.dumps(sorted_dict(item), protocol=protocol), usedforsecurity=False # type: ignore
).hexdigest()
return f"{cache_key}".encode()


Expand Down