Skip to content

Decorators

deprecated(reason)

Create a decorator that marks functions as deprecated.

This decorator will emit a warning when the decorated function is called, indicating that the function is deprecated and providing a reason.

Parameters:

Name Type Description Default
reason str

The reason why the function is deprecated.

required

Returns:

Name Type Description
callable

A decorator function that can be applied to mark functions as deprecated.

Source code in inference_sdk/utils/decorators.py
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
def deprecated(reason: str):
    """Create a decorator that marks functions as deprecated.

    This decorator will emit a warning when the decorated function is called,
    indicating that the function is deprecated and providing a reason.

    Args:
        reason (str): The reason why the function is deprecated.

    Returns:
        callable: A decorator function that can be applied to mark functions as deprecated.
    """

    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            warnings.warn(
                f"{func.__name__} is deprecated: {reason}",
                category=InferenceSDKDeprecationWarning,
                stacklevel=2,
            )
            return func(*args, **kwargs)

        return wrapper

    return decorator

experimental(info)

Create a decorator that marks functions as experimental.

This decorator will emit a warning when the decorated function is called, indicating that the function is experimental and providing additional information.

Parameters:

Name Type Description Default
info str

Information about the experimental status of the function.

required

Returns:

Name Type Description
callable

A decorator function that can be applied to mark functions as experimental.

Source code in inference_sdk/utils/decorators.py
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
def experimental(info: str):
    """Create a decorator that marks functions as experimental.

    This decorator will emit a warning when the decorated function is called,
    indicating that the function is experimental and providing additional information.

    Args:
        info (str): Information about the experimental status of the function.

    Returns:
        callable: A decorator function that can be applied to mark functions as experimental.
    """

    def decorator(func):
        @functools.wraps(func)
        def wrapper(*args, **kwargs):
            warnings.warn(
                f"{func.__name__} is experimental: {info}",
                category=InferenceSDKDeprecationWarning,
                stacklevel=2,
            )
            return func(*args, **kwargs)

        return wrapper

    return decorator