Skip to content

deprecation

Decorator to mark a function, class, or attribute as deprecated.

This decorator will issue a warning when the decorated function, class, or attribute is used, indicating that it is deprecated and may be removed in a future version.

Examples:

@deprecated
def my_function():
    pass

@deprecated(old="old_function", new="new_function", since=(1, 0, 0), remove=(2, 0, 0))
def my_function():
    pass

Attributes

C module-attribute

C = TypeVar('C', bound=Callable[..., Any])

Functions

deprecated

deprecated(func: C) -> C
deprecated(
    *,
    old: Optional[str] = None,
    new: Optional[str] = None,
    since: Optional[Tuple[int, int, int]] = None,
    remove: Optional[Tuple[int, int, int]] = None
) -> Callable[[C], C]
deprecated(
    func: Optional[C] = None,
    *,
    old: Optional[str] = None,
    new: Optional[str] = None,
    since: Optional[Tuple[int, int, int]] = None,
    remove: Optional[Tuple[int, int, int]] = None
) -> Union[C, Callable[[C], C]]

Decorator to mark a function, class, or attribute as deprecated.

This decorator will issue a warning when the decorated function, class, or attribute is used, indicating that it is deprecated and may be removed in a future version.

Note that this will not work with some classes, notably Pydantic models.

Parameters:

  • func (Optional[C], default: None ) –

    The function, class, or attribute to be marked as deprecated.

  • old (Optional[str], default: None ) –

    The old function, class, or attribute name that is deprecated.

  • new (Optional[str], default: None ) –

    The new function, class, or attribute name that should be used instead.

  • since (Optional[Tuple[int, int, int]], default: None ) –

    A tuple representing the version (major, minor, patch) since the function, class, or attribute is deprecated.

  • remove (Optional[Tuple[int, int, int]], default: None ) –

    A tuple representing the version (major, minor, patch) in which the function, class, or attribute will be removed.

Returns:

  • Union[C, Callable[[C], C]]

    The wrapped function, class, or attribute.