Deprecat Decorator

2.1.3 · active · verified Thu Apr 16

The `deprecat` library provides a Python `@deprecat` decorator for marking classes, functions, and methods as deprecated. It also includes functionality to deprecate specific arguments within a function using `@deprecat.deprecated_args`. Maintained on GitHub, it's currently at version 2.1.3 and has a moderate release cadence, with the latest significant updates focusing on bug fixes and new features like `remove_version`.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates basic usage of the `@deprecat` decorator on functions and methods, as well as marking specific arguments as deprecated using `@deprecat.deprecated_args`.

from deprecat import deprecat
import warnings

@deprecat(reason="This function is old, use new_sum instead", version="2.0.0")
def old_sum(a, b):
    return a + b

class MyClass:
    @deprecat(reason="This method is outdated", version="2.1.0")
    def old_method(self):
        return "Hello from old method"

@deprecat(reason="This function's 'b' argument is deprecated", version='2.1.1')
@deprecat.deprecated_args(version='2.1.1', deprecated_argument='b')
def my_func(a, b):
    return a * b

# Suppress deprecation warnings for cleaner output in quickstart
with warnings.catch_warnings():
    warnings.simplefilter("ignore", DeprecationWarning)
    print(f"Old sum: {old_sum(1, 2)}")
    obj = MyClass()
    print(f"Old method output: {obj.old_method()}")
    print(f"Function with deprecated arg: {my_func(3, b=4)}")

view raw JSON →