Skip to content

Commit 9b90028

Browse files
committed
Use the custom function for hash to ensure support for python 3.8
1 parent c3ba7b2 commit 9b90028

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

src/mlx/warnings/code_quality.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import hashlib
22
from pathlib import Path
3-
3+
import sys
44

55
class Finding:
66
"""Code quality violation"""
@@ -32,9 +32,9 @@ def fingerprint(self):
3232
4. Step 3 is repeated until a unique hash is obtained.
3333
"""
3434
hashable_string = f"{self.severity}{self.path}{self.description}"
35-
new_hash = hashlib.md5(str(hashable_string).encode("utf-8"), usedforsecurity=False).hexdigest()
35+
new_hash = self._md5_hash(str(hashable_string).encode("utf-8"))
3636
while new_hash in self.fingerprints and self.fingerprints[new_hash] != self:
37-
new_hash = hashlib.md5(f"{hashable_string}{new_hash}".encode(), usedforsecurity=False).hexdigest()
37+
new_hash = self._md5_hash(f"{hashable_string}{new_hash}".encode())
3838
type(self).fingerprints[new_hash] = self
3939
return new_hash
4040

@@ -114,6 +114,11 @@ def column(self, value):
114114
raise ValueError(f"Expected column number greater than 0; Got {column_number}")
115115
self._column = column_number
116116

117+
def _md5_hash(self, data: bytes) -> str:
118+
if sys.version_info >= (3, 9):
119+
return hashlib.md5(data, usedforsecurity=False).hexdigest()
120+
return hashlib.md5(data).hexdigest()
121+
117122
def to_dict(self):
118123
"""Returns the code quality finding as dictionary with a unique fingerprint.
119124

0 commit comments

Comments
 (0)