fix(deprecated): change MeanAveragePrecision to frozen dataclass and enhance deprecated decorator for classes

This commit is contained in:
Onuralp SEZER committed 2025-07-15 22:41:25 +03:00
1 parent 2b47d8e4cc
commit 5d6f5bfde3
2 files changed
+19 -7

No files matched your search

+1 -1
View File
@@ -500,7 +500,7 @@ class ConfusionMatrix:
"`supervision.metrics.mean_average_precision.MeanAveragePrecision` instead. The "
"deprecated implementation provides results that are inconsistent with pycocotools."
)
@dataclass()
@dataclass(frozen=True)
class MeanAveragePrecision:
"""
!!! deprecated "Deprecated"
+18 -6
View File
@@ -114,13 +114,25 @@ def deprecated_parameter(
def deprecated(reason: str):
def decorator(func):
@functools.wraps(func)
def wrapper(*args, **kwargs):
warn_deprecated(f"{func.__name__} is deprecated: {reason}")
return func(*args, **kwargs)
def decorator(cls_or_func):
if inspect.isclass(cls_or_func):
original_init = cls_or_func.__init__
return wrapper
@functools.wraps(original_init)
def new_init(self, *args, **kwargs):
warn_deprecated(f"{cls_or_func.__name__} is deprecated: {reason}")
original_init(self, *args, **kwargs)
cls_or_func.__init__ = new_init
return cls_or_func
else:
@functools.wraps(cls_or_func)
def wrapper(*args, **kwargs):
warn_deprecated(f"{cls_or_func.__name__} is deprecated: {reason}")
return cls_or_func(*args, **kwargs)
return wrapper
return decorator