diff --git a/supervision/detection/tools/polygon_zone.py b/supervision/detection/tools/polygon_zone.py index 4240c952..372db7a3 100644 --- a/supervision/detection/tools/polygon_zone.py +++ b/supervision/detection/tools/polygon_zone.py @@ -10,6 +10,7 @@ from supervision.draw.color import Color from supervision.draw.utils import draw_polygon, draw_text from supervision.geometry.core import Position from supervision.geometry.utils import get_polygon_center +from supervision.utils.internal import deprecated_parameter class PolygonZone: @@ -26,6 +27,11 @@ class PolygonZone: mask (np.ndarray): The 2D bool mask for the polygon zone """ + @deprecated_parameter( + old_param="triggering_position", + new_param="triggering_anchors", + map_func=lambda x: [x], + ) def __init__( self, polygon: np.ndarray, diff --git a/supervision/utils/internal.py b/supervision/utils/internal.py index 031f5be1..fc9e4d72 100644 --- a/supervision/utils/internal.py +++ b/supervision/utils/internal.py @@ -1,5 +1,34 @@ import functools import warnings +from typing import Callable + + +def deprecated_parameter(old_param: str, new_param: str, map_func: Callable = lambda x: x): + def decorator(func): + @functools.wraps(func) + def wrapper(*args, **kwargs): + if old_param in kwargs: + # In case of a method, display also the class name. + if args and hasattr(args[0], "__class__"): + class_name = args[0].__class__.__name__ + function_name = f"{class_name}.{func.__name__}" + else: + function_name = func.__name__ + + # Display deprecation warning + warnings.warn( + f"Warning: '{old_param}' in '{function_name}' is deprecated: use '{new_param}' instead.", + category=DeprecationWarning, + stacklevel=2, + ) + # Map old_param to new_param + kwargs[new_param] = map_func(kwargs.pop(old_param)) + + return func(*args, **kwargs) + + return wrapper + + return decorator def deprecated(reason: str):