Skip to content

Commit

Permalink
Warn once
Browse files Browse the repository at this point in the history
  • Loading branch information
justinchuby committed Oct 23, 2024
1 parent e6c36dd commit ce95d91
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions onnxscript/_internal/deprecation.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
T = TypeVar("T")


@functools.lru_cache(maxsize=1024)
def _warn_once(message: str):
"""Issue a FutureWarning only once per message."""
warnings.warn(message, category=FutureWarning, stacklevel=3)


def deprecated(since: str, removed_in: str, instructions: str) -> Callable[[T], T]:
"""Marks functions as deprecated.
Expand All @@ -30,12 +36,10 @@ def deprecated(since: str, removed_in: str, instructions: str) -> Callable[[T],
def decorator(function):
@functools.wraps(function)
def wrapper(*args, **kwargs):
warnings.warn(
_warn_once(
f"'{function.__module__}.{function.__qualname__}' "
f"is deprecated in version {since} and will be "
f"removed in {removed_in}. Please {instructions}.",
category=FutureWarning,
stacklevel=2,
)
return function(*args, **kwargs)

Expand Down

0 comments on commit ce95d91

Please sign in to comment.