Merge pull request #962 from roboflow/feat/supervision/warnings

fix: 🐞 Custom warning type 'SupervisionWarning' added
This commit is contained in:
Onuralp SEZER
2024-02-29 19:27:04 +03:00
committed by GitHub
+28 -3
View File
@@ -1,8 +1,33 @@
import functools
import os
import warnings
from typing import Callable
warnings.simplefilter("always", DeprecationWarning)
class SupervisionWarnings(Warning):
"""Supervision warning category.
Set the deprecation warnings visibility for Supervision library.
You can set the environment variable SUPERVISON_DEPRECATION_WARNING to '0' to
disable the deprecation warnings.
"""
pass
def format_warning(msg, category, filename, lineno, line=None):
"""
Format a warning the same way as the default formatter, but also include the
category name in the output.
"""
return f"{category.__name__}: {msg}\n"
warnings.formatwarning = format_warning
if os.getenv("SUPERVISON_DEPRECATION_WARNING") == "0":
warnings.simplefilter("ignore", SupervisionWarnings)
else:
warnings.simplefilter("always", SupervisionWarnings)
def deprecated_parameter(
@@ -63,7 +88,7 @@ def deprecated_parameter(
new_parameter=new_parameter,
**message_kwargs,
),
category=DeprecationWarning,
category=SupervisionWarnings,
stacklevel=2,
)
@@ -82,7 +107,7 @@ def deprecated(reason: str):
def wrapper(*args, **kwargs):
warnings.warn(
f"{func.__name__} is deprecated: {reason}",
category=DeprecationWarning,
category=SupervisionWarnings,
stacklevel=2,
)
return func(*args, **kwargs)