refactor: ✨ improve validate_resolution function to have type,value check similar to other validate functions
This commit is contained in:
1 file changed
+10
-3
@@ -1,4 +1,4 @@
|
||||
from typing import Any, Dict
|
||||
from typing import Any, Dict, Tuple
|
||||
|
||||
import numpy as np
|
||||
|
||||
@@ -140,11 +140,18 @@ def validate_keypoints_fields(
|
||||
validate_data(data, n)
|
||||
|
||||
|
||||
def validate_resolution(resolution):
|
||||
def validate_resolution(resolution: Any) -> Tuple[int, int]:
|
||||
if not (isinstance(resolution, tuple) and len(resolution) == 2):
|
||||
raise ValueError(
|
||||
f"resolution must be a tuple of two integers, got {type(resolution)} with value {resolution}"
|
||||
)
|
||||
w, h = resolution
|
||||
if not (isinstance(w, int) and isinstance(h, int)):
|
||||
raise ValueError(
|
||||
f"Both elements in resolution must be integers. Got types ({type(w)}, {type(h)})"
|
||||
)
|
||||
if w <= 0 or h <= 0:
|
||||
raise ValueError(
|
||||
f"Both dimensions in resolution must be positive. Got ({w}, {h})."
|
||||
)
|
||||
|
||||
return w, h
|
||||
Reference in new issue
Block a user