Skip to content

Commit c4958e4

Browse files
authored
move supported types check earlier
1 parent b72f5ff commit c4958e4

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/cleanvision/issue_managers/duplicate_issue_manager.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@
1717

1818
def get_hash(image: Image.Image, params: Dict[str, Any]) -> str:
1919
hash_type, hash_size = params["hash_type"], params.get("hash_size", None)
20+
supported_types = ["md5", "whash", "phash", "ahash", "dhash", "chash"]
21+
if not hash_type in supported_types:
22+
raise ValueError(f"Hash type `{hash_type}` is not supported. Must be one of: {supported_types}")
23+
2024
if hash_type == "md5":
2125
pixels = np.asarray(image)
2226
return hashlib.md5(pixels.tobytes()).hexdigest()
@@ -33,8 +37,6 @@ def get_hash(image: Image.Image, params: Dict[str, Any]) -> str:
3337
return str(imagehash.dhash(image, hash_size=hash_size))
3438
elif hash_type == "chash":
3539
return str(imagehash.colorhash(image, binbits=hash_size))
36-
else:
37-
raise ValueError("Hash type not supported")
3840

3941

4042
def compute_hash(

0 commit comments

Comments
 (0)