Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/onnx/_deprecated.py: 78%
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
Shortcuts on this page
r m x toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1# Copyright (c) ONNX Project Contributors
2#
3# SPDX-License-Identifier: Apache-2.0
4from __future__ import annotations
6import functools
7import warnings
8from typing import TYPE_CHECKING, ParamSpec, TypeVar
10if TYPE_CHECKING:
11 from collections.abc import Callable
13_P = ParamSpec("_P")
14_R = TypeVar("_R")
17def deprecated(message: str) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]:
18 """Warn at the caller of a deprecated function, preserving its signature."""
20 def decorate(function: Callable[_P, _R]) -> Callable[_P, _R]:
21 function.__dict__["__deprecated__"] = message
23 @functools.wraps(function)
24 def wrapped(*args: _P.args, **kwargs: _P.kwargs) -> _R:
25 warnings.warn(message, DeprecationWarning, stacklevel=2)
26 return function(*args, **kwargs)
28 return wrapped
30 return decorate