Merge pull request #962 from roboflow/feat/supervision/warnings
fix: 🐞 Custom warning type 'SupervisionWarning' added
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user