From 5d866fd8a190368a765783581b344df536ec49aa Mon Sep 17 00:00:00 2001 From: Onuralp SEZER Date: Mon, 14 Jul 2025 14:14:03 +0300 Subject: [PATCH] =?UTF-8?q?refactor:=20=20=E2=9C=A8=20=20improve=20validat?= =?UTF-8?q?e=5Fresolution=20function=20to=20have=20type,value=20check=20si?= =?UTF-8?q?milar=20to=20other=20validate=20functions?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- supervision/validators/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/supervision/validators/__init__.py b/supervision/validators/__init__.py index 7b1f00eb..4d21493b 100644 --- a/supervision/validators/__init__.py +++ b/supervision/validators/__init__.py @@ -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