File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import hashlib
22from pathlib import Path
3-
3+ import sys
44
55class 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
You can’t perform that action at this time.
0 commit comments