Typing Stubs for Deprecated

1.3.1.20260402 · active · verified Sun Apr 05

This is a typeshed stub package that provides static type annotations for the 'Deprecated' Python library. It enables type checkers like Mypy and Pyright to analyze code using the `Deprecated` library, which offers a `@deprecated` decorator for marking functions, methods, or classes as deprecated and emitting runtime warnings. The `types-deprecated` package is part of the `typeshed` project and its release cadence is tied to typeshed updates, aiming for compatibility with `Deprecated~=1.3.1`.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to apply the `@deprecated` decorator to functions and classes from the `Deprecated` library. It also includes an example of using `@deprecated_params` for specific arguments. Crucially, it shows how to enable `DeprecationWarning` messages, which are often ignored by default in Python, so you can see the warnings generated by using deprecated code.

import warnings
from deprecated import deprecated

# Enable DeprecationWarnings to be visible (they are often ignored by default)
warnings.simplefilter('always', DeprecationWarning)

@deprecated(reason="Use new_function instead")
def old_function(a: int, b: int) -> int:
    """This is an old function."""
    return a + b

@deprecated(version='1.2.0', reason="Use NewClass instead")
class OldClass:
    def __init__(self, value: str):
        self.value = value

    def get_value(self) -> str:
        return self.value


def new_function(x: int, y: int) -> int:
    """This is the new function."""
    return x * y


# Using the deprecated function and class
result = old_function(5, 3)
print(f"Result from old_function: {result}")

obj = OldClass("hello")
print(f"Value from OldClass: {obj.get_value()}")


# Expected usage of the new function
new_result = new_function(5, 3)
print(f"Result from new_function: {new_result}")

# Example of using a deprecated parameter (requires deprecated.params)
from deprecated.params import deprecated_params

@deprecated_params('old_arg', reason='Use new_arg instead')
def example_function(new_arg: str, old_arg: str = 'default') -> None:
    print(f"Called with new_arg: {new_arg}, old_arg: {old_arg}")

example_function(new_arg='modern value', old_arg='legacy value')

# Restore default warning filter (optional)
warnings.simplefilter('default', DeprecationWarning)

view raw JSON →