Skip to content

Python @deprecated decorator to deprecate old python classes, functions or methods.

License

Notifications You must be signed in to change notification settings

laurent-laporte-pro/deprecated

Repository files navigation

Deprecated Decorator

Python @deprecated decorator to deprecate old python classes, functions or methods.

Build Status Build status Coverage Status GitHub version GitHub license Documentation Status

Installation

pip install Deprecated

Classic usage

To use this, decorate your deprecated function with @deprecated decorator:

from deprecated import deprecated


@deprecated
def some_old_function(x, y):
    return x + y

You can also decorate a class or a method:

from deprecated import deprecated


class SomeClass(object):
    @deprecated
    def some_old_method(self, x, y):
        return x + y


@deprecated
class SomeOldClass(object):
    pass

You can give a "reason" message to help the developer to choose another function/class:

from deprecated import deprecated


@deprecated(reason="use another function")
def some_old_function(x, y):
    return x + y

Sphinx directives

Have you ever wonder how to document that some functions, classes, methods, etc. are deprecated? This is now possible with the integrated Sphinx directives:

from deprecated.sphinx import deprecated
from deprecated.sphinx import versionadded
from deprecated.sphinx import versionchanged


@versionadded(version='1.0', reason="This function is new")
def function_one():
    '''This is the function one'''


@versionchanged(version='1.0', reason="This function is modified")
def function_two():
    '''This is the function two'''


@deprecated(version='1.0', reason="This function will be removed soon")
def function_three():
    '''This is the function three'''

Authors

The authors of this library are: Marcos CARDOSO, and Laurent LAPORTE.

The original code was made in this StackOverflow post by Leandro REGUEIRO, Patrizio BERTONI, and Eric WIESER.